Dashboards & Visualizations

Setting different token value depending on token value

light_of_sirius
Explorer

Hello,

i am trying to set the color of writing depending on the user input, i.e., he inputs two numbers and if number 1 is larger than number 2 then the writing is green.

This problem is related to my actual problem and supposed to simplify the setting.

Feel free to point out any rudimentary/logical problems in the code, i am new to html/xml and find everything quite confusing and (weirdly?) complicated.

Thank you 🙂

 

 

 

<form>
  <label>condition</label>
  <init>
    <unset token="dif"></unset>
  </init>
  <fieldset submitButton="false">
    <input type="text" token="field1">
      <label>field1</label>
    </input>
    <input type="text" token="field2">
      <label>field2</label>
    </input>
  </fieldset>
  <row>
    <panel>
      <single>
        <search>
          <query>
            index = _internal
            |eval dif = $field1$-$field2$
            |table dif
          </query>
          <done>
            <condition match="$result.dif$>0">
              <set token="color1">"green"</set>
            </condition>
            <condition match="$result.dif$<0">
              <set token="color1">"red"</set>
            </condition>
          </done>
        </search>
      </single>
    </panel>
  </row>
  <row>
    <panel>
      <html>
        <body>
          <div>
            <p color="$color1$">Number 1 is larger than number 2!</p>
          </div>
        </body>
      </html>
    </panel>
  </row>
</form>

 

 

 

 

 

Labels (2)
0 Karma
1 Solution

renjith_nair
Legend

Try

 

<form>
  <label>condition</label>
  <init>
    <unset token="dif"></unset>
  </init>
  <fieldset submitButton="false">
    <input type="text" token="field1">
      <label>field1</label>
    </input>
    <input type="text" token="field2">
      <label>field2</label>
    </input>
  </fieldset>
  <row>
    <panel>
      <single>
        <search>
          <query>
            |makeresults
            |eval dif = $field1$-$field2$
            |table dif
          </query>
          <done>
            <condition match="$result.dif$ &gt; 0">
              <set token="color1">#dc4e41</set>
              <set token="status">greater than</set>
            </condition>
            <condition match="$result.dif$ &lt; 0">
              <set token="color1">#53a051</set>
              <set token="status">lesser than</set>
            </condition>
            <condition>
              <set token="color1">#0877a6</set>
              <set token="status">equal to</set>
            </condition>
          </done>
        </search>
      </single>
    </panel>
  </row>
  <row>
    <panel>
      <html>
        <body>
          <div>
            <p>
              <font color="$color1$">Number $field1$ is $status$ number $field2$ ! </font>
            </p>
          </div>
        </body>
      </html>
    </panel>
  </row>
</form>

 

 

---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

light_of_sirius
Explorer

Thank you, it works. 

0 Karma

renjith_nair
Legend

Try

 

<form>
  <label>condition</label>
  <init>
    <unset token="dif"></unset>
  </init>
  <fieldset submitButton="false">
    <input type="text" token="field1">
      <label>field1</label>
    </input>
    <input type="text" token="field2">
      <label>field2</label>
    </input>
  </fieldset>
  <row>
    <panel>
      <single>
        <search>
          <query>
            |makeresults
            |eval dif = $field1$-$field2$
            |table dif
          </query>
          <done>
            <condition match="$result.dif$ &gt; 0">
              <set token="color1">#dc4e41</set>
              <set token="status">greater than</set>
            </condition>
            <condition match="$result.dif$ &lt; 0">
              <set token="color1">#53a051</set>
              <set token="status">lesser than</set>
            </condition>
            <condition>
              <set token="color1">#0877a6</set>
              <set token="status">equal to</set>
            </condition>
          </done>
        </search>
      </single>
    </panel>
  </row>
  <row>
    <panel>
      <html>
        <body>
          <div>
            <p>
              <font color="$color1$">Number $field1$ is $status$ number $field2$ ! </font>
            </p>
          </div>
        </body>
      </html>
    </panel>
  </row>
</form>

 

 

---
What goes around comes around. If it helps, hit it with Karma 🙂
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...