All Apps and Add-ons

How to change a TextField value and execute a search using the changed TextField value on every click of a search button?

Explorer

Having following structure in dashboard
Textfield 1
------|-TextField 2
-------------|-Button 1
-------------------|-Button2
------------------------|-Search

I want that:
1. every time I click button 1, it should decrease the values in TextFields by 1 and execute search with changed textfield values(search uses values of textfield).
2. every time I click button 2, it should increase the values in TextFields by 1 and execute search with changed textfield values(search uses values of textfield).

I added a custom Behaviour method in application.js that on click of button 1, executes the search and decreases the value in textfields by 1. It works fine for the first time, but when second time I click the button, it updates the textfield values and executes search but not with the updated TextField values. Search is using initial textfield values but not the updated values.

Please suggest what can be done to make things work fine.
Thanks 🙂

1 Solution

Explorer

I implemented it using Sideview Utils and java script.

If the current time-range is x to x+y, click the < button would render the search with x-y/2 to x+y/2.
Similarly, clicking the > button would render the search with x+y/2 to x+3y/2.

Basically, sliding the timechart by half of the time-range interval.

View solution in original post

Explorer

I implemented it using Sideview Utils and java script.

If the current time-range is x to x+y, click the < button would render the search with x-y/2 to x+y/2.
Similarly, clicking the > button would render the search with x+y/2 to x+3y/2.

Basically, sliding the timechart by half of the time-range interval.

View solution in original post

Splunk Employee
Splunk Employee

Is your answer the solution to your question? If yes and you would like to close out your post, don't forget to click "Accept". Thanks!

0 Karma

SplunkTrust
SplunkTrust

So, for example, the TextField1 might contain a number like 200, and TextField2 might have 300. Clicking Button1 you want them to change to 199, 299, and if instead I click Button2 you want them to change to 201 and 301?

What are the numbers representing out of curiosity?

Is it OK if the eventual solution is a single textfield whose value is a range like "100,200"? Either way the textfield(s) are going to need some JS to validate user input so it might be easier to have only the one field.

And to obey the general principle of "changes move downstream", in my eventual answer I'm most likely going to change the order so the TextField(s) are below the button. Curious if that matters to you for any other reason.

0 Karma

Explorer

Yes. If TextField1 contain 200 and TextField2 contain 300, on click it should change to 199 and 299 and similarly with the other button. These numbers act as timerange for the search. Number in TextField1 represents earliest whereas number in TextField2 represents latest value for the search.
Following is the code snippet:


<param name="name">earl</param>
<param name="float">left</param>
<param name="template">$value$h</param>
<param name="label"></param>
<param name="default">-2</param>
<module name="TextField" layoutPanel="panel_row1_col1" autoRun="True">
  <param name="name">late</param>
  <param name="template">$value$h</param>
  <param name="default">-0</param>
  <module name="Button">
    <param name="label">Previous 2 Hours</param>
    <param name="allowSoftSubmit">True</param>     
    <module name="Search" layoutPanel="panel_row1_col1" autoRun="true">
      <param name="search">  <![CDATA[index=some_index earliest=$earl$ latest=$late$ | eval time = strftime(_time, " %D - %H")| chart sum(count(param)) by time host]]></param>

Both the TextFields will be hidden and will not be accessible to the user. Only code will use it. To pass different values to earliest and latest in search, I've taken two separate TextFields. When pressing one of the button, search will execute with different timerange and thus will shift the chart to previous 1 hour or next 1 hour. This will create a time-traversing effect.

I've overriden onContextChange() with custom behavior on button that will execute search as well as it ll change the TextField Values depending on which button pressed. So when I next time press it, search will execute with new earliest and latest values taken from the TextFields.

Order of module doesn't matter if its going to work fine. 🙂
Thanks !!

0 Karma