Getting Data In
Highlighted

How to add dynamic value as default value in check box ?

Communicator

Hello Everyone,

Can we use dynamic value as default value for check box? currently am trying below code, but unfortunately don't know how to add my dynamic value current_month_year as checked in my form

<input type="checkbox" token="currentdate">
      <label>date</label>
        <choice value="*">ALL</choice>
        <default>current_month_year</default>

     <fieldForLabel>currentdate</fieldForLabel>
      <fieldForValue>current_month_year</fieldForValue>
      <search>
      <query>| makeresults | eval current_month_year=strftime(now(),"%Y-%m") 
| table current_month_year</query>
</search>

      <valuePrefix>"</valuePrefix>
      <valueSuffix>"</valueSuffix>

      </input>

Can any one help me here

0 Karma
Highlighted

Re: How to add dynamic value as default value in check box ?

Contributor

Hi,

This should do it:

<default>$current_month_year$</default>
0 Karma
Highlighted

Re: How to add dynamic value as default value in check box ?

Communicator

Hello Knielsen,

its taking as string "$currentmonthyear$" its not taking value

0 Karma
Highlighted

Re: How to add dynamic value as default value in check box ?

Legend

@snehalk, Checkbox input does not seem to accept token as default field.
Based on the example, seems like you want to use checkbox as toggle between All and Current Month. Instead of checkbox can you use radio input?

 <input type="radio" token="currentdate">
       <label>date</label>
       <choice value="*">ALL</choice>
       <default>$tokCurrentMonthYear$</default>
       <fieldForLabel>current_month_year</fieldForLabel>
       <fieldForValue>current_month_year</fieldForValue>
       <search>
           <query>| makeresults 
             | eval current_month_year=strftime(now(),"%Y-%m") 
             | table current_month_year</query>
           <progress>
                   <set token="tokCurrentMonthYear">$result.current_month_year$</set>
           </progress> 
       </search>
       <valuePrefix>"</valuePrefix>
       <valueSuffix>"</valueSuffix>
 </input>

Radio input allows passing default value as token: <default>$tokCurrentMonthYear$</default>. The same does not work with checkbox which treats it as string. This seems to be bug with Checkbox which handles multiple value. So your task would be achievable only through custom JavaScript if you have a constraint to use checkbox.




| eval message="Happy Splunking!!!"


View solution in original post

Highlighted

Re: How to add dynamic value as default value in check box ?

Communicator

Awesome!! Thank you so much!! @niketnilay, its working as expected! now i can go with radio input, instated of checkbox for now.

0 Karma
Highlighted

Re: How to add dynamic value as default value in check box ?

Communicator

@niketnilay, can we do the change in the order and label for radio? that is right now we are getting option like
1. All
2. 2017-07

Can we get like
1. Current Month

2. All

Here "Current Month" contain value "2017-07"?

Can you please help me here?

0 Karma
Highlighted

Re: How to add dynamic value as default value in check box ?

Legend

HI snehalk, Static options are displayed first followed by the results from the Dynamic Query. You can remove the static <choice> All and move the same to Dynamic option using the following query:

| makeresults 
| eval current_month_year=strftime(now(),"%Y-%m") 
| append [
           | makeresults 
           | eval current_month_year="*" ]
| table current_month_year

Another way to use query would be to use the following query,

| makeresults 
| eval current_month_year=strftime(now(),"%Y-%m") 
| appendcols [
           | makeresults 
           | eval All="*" ]
| fields - _time
| transpose column_name="label"
| reverse
| rename "row 1" as value



| eval message="Happy Splunking!!!"


0 Karma