Dashboards & Visualizations
Highlighted

Can I pass a multivalue result into a checkbox input?

Explorer

In the below run-anywhere dashboard. I have a search that produces a multivalue result called "products". The search will determine which products to select in the checkbox input, which then affects another search (not shown here - use your imagination).

If I change the | stats values(product) as products to | stats values(first) as products, then the single checkbox will be checked. But with multiple values, nothing is checked. I have a text field with the label set to the form.products token so that it's possible to see that the multivalue is being converted into a comma-delimited string. What format does this need to be in for the checkbox input to accept multiple values?

<form>
  <label>Test_Checkbox_Tokens</label>
  <search id="base">
    <query>| makeresults | eval product="Product_1,Product_2" | makemv product  delim=","| stats values(product) as products
  </query>
    <earliest>-30d@d</earliest>
    <latest>now</latest>
    <sampleRatio>1</sampleRatio>
    <done>
      <set token="form.products">$result.products$</set>
    </done>
  </search>
  <fieldset submitButton="false">
    <input type="checkbox" token="products">
      <label>Products</label>
      <choice value="Product_1">Product 1</choice>
      <choice value="Product_2">Product 2</choice>
      <choice value="Product_3">Product 3</choice>
      <delimiter> </delimiter>
    </input>
    <input type="text" token="field1">
      <label>Selected Products: $form.products$</label>
    </input>
  </fieldset>
  <row>
    <panel>
      <table>
        <search base="base"></search>
      </table>
    </panel>
  </row>
</form>
0 Karma
Highlighted

Re: Can I pass a multivalue result into a checkbox input?

Champion

Hi @jlemley

Please try the following with javascript and let me know any issues,

<form script="checkbox.js">
  <label>Test_Checkbox_Tokens</label>
  <search id="base">
    <query>| makeresults | eval product="Product_1,Product_3" | makemv product  delim=","| stats values(product) as products
   </query>
    <earliest>-30d@d</earliest>
    <latest>now</latest>
    <sampleRatio>1</sampleRatio>
    <done>
      <set token="product_results">$result.products$</set>
    </done>
  </search>
  <fieldset submitButton="false">
    <input type="checkbox" token="products" id="rk">
      <label>Products</label>
      <choice value="Product_1">Product 1</choice>
      <choice value="Product_2">Product 2</choice>
      <choice value="Product_3">Product 3</choice>
    </input>
    <input type="text" token="field1">
      <label>Selected Products: $form.products$</label>
    </input>
  </fieldset>
  <row>
    <panel>
      <table>
        <search base="base"></search>
      </table>
    </panel>
  </row>
</form>

javascript: checkbox.js

require([
    "splunkjs/mvc",
    "splunkjs/mvc/checkboxgroupview",
    "splunkjs/mvc/simplexml/ready!"
], function(mvc, CheckboxGroupView) {

    var tokens = mvc.Components.get("default");
    var tokenValue = tokens.get("product_results");
    var temp = new Array();
    temp = tokenValue.split(",");
    splunkjs.mvc.Components.get("rk").settings.set("initialValue",temp );
    splunkjs.mvc.Components.get("rk").render();
});
0 Karma
Highlighted

Re: Can I pass a multivalue result into a checkbox input?

Explorer

Thanks for the reply! This works in the console in Splunk 7.2, but not when I implement it in a JavaScript file. I forgot to mention that my production environment is running 6.5.9, and it does not even work in the console in that version.

0 Karma
Highlighted

Re: Can I pass a multivalue result into a checkbox input?

Champion

Hi @jlemley

Try with the following javascript, and use splunkjs.mvc.Components.getInstance instead of splunkjs.mvc.Components.get. I had verified in 6.5.9

require([
    "splunkjs/mvc",
    "splunkjs/mvc/checkboxgroupview",
    "splunkjs/mvc/simplexml/ready!"
], function(mvc, CheckboxGroupView) {
    var tokens = mvc.Components.get("default");
    var tokenValue = tokens.get("product_results");
    var temp = new Array();
     temp = tokenValue.split(",");

    splunkjs.mvc.Components.getInstance("rk").settings.set("initialValue",temp);
    splunkjs.mvc.Components.getInstance("rk").render();
});
0 Karma
Highlighted

Re: Can I pass a multivalue result into a checkbox input?

Champion

Try the above script and let me know

0 Karma
Highlighted

Re: Can I pass a multivalue result into a checkbox input?

Champion

@jlemley, Has it resolved?

0 Karma
Highlighted

Re: Can I pass a multivalue result into a checkbox input?

Explorer

I just tested this morning, and it still does not check the boxes. I did a console log output and confirmed that the token is being read and placed into an array, and that the "rk" element is being found, but the "set" and "render" do not seem to be doing what is expected. Thanks for trying!

0 Karma
Speak Up for Splunk Careers!

We want to better understand the impact Splunk experience and expertise has has on individuals' careers, and help highlight the growing demand for Splunk skills.