Dashboards & Visualizations

Can I pass a multivalue result into a checkbox input?

jlemley
Path Finder

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

vnravikumar
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

jlemley
Path Finder

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

vnravikumar
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

sntos05
Loves-to-Learn Everything

This helps me reach to my solution with a little change adding it here might help someone.

 

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").val(temp);    
});

 

0 Karma

vnravikumar
Champion

Try the above script and let me know

0 Karma

vnravikumar
Champion

@jlemley, Has it resolved?

0 Karma

jlemley
Path Finder

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
Get Updates on the Splunk Community!

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...

Updated Data Management and AWS GDI Inventory in Splunk Observability

We’re making some changes to Data Management and Infrastructure Inventory for AWS. The Data Management page, ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...