<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Set multiselect with JavaScript in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/570345#M46858</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/238353"&gt;@puet&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please share your sample code and use case?&lt;/P&gt;&lt;P&gt;KV&lt;/P&gt;</description>
    <pubDate>Sat, 09 Oct 2021 16:54:08 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2021-10-09T16:54:08Z</dc:date>
    <item>
      <title>Set multiselect with JavaScript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/569887#M46816</link>
      <description>&lt;P&gt;I know how to set Values.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;multiselect&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;val&lt;/SPAN&gt;&lt;SPAN&gt;(value_&lt;/SPAN&gt;&lt;SPAN&gt;array&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BUT:&lt;/STRONG&gt;&amp;nbsp;&lt;BR /&gt;Is there a way to set the labels to a different value (not the actual value)?&lt;BR /&gt;&lt;U&gt;For Example&lt;/U&gt;: i want to be able to select the country by its name but in the search i use the country code.&lt;/P&gt;&lt;P&gt;&lt;U&gt;Something like:&lt;/U&gt;&lt;BR /&gt;multiselect.label(lable_array);&lt;/P&gt;&lt;P&gt;&lt;U&gt;or:&lt;/U&gt;&lt;BR /&gt;multiselect.val(value_array , label_array);&lt;/P&gt;&lt;P&gt;I tried an array with label-value pairs but it did not work.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 13:27:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/569887#M46816</guid>
      <dc:creator>puet</dc:creator>
      <dc:date>2021-10-06T13:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Set multiselect with JavaScript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/570345#M46858</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/238353"&gt;@puet&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please share your sample code and use case?&lt;/P&gt;&lt;P&gt;KV&lt;/P&gt;</description>
      <pubDate>Sat, 09 Oct 2021 16:54:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/570345#M46858</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2021-10-09T16:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Set multiselect with JavaScript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/570418#M46868</link>
      <description>&lt;P&gt;I realized I can just use initial&amp;nbsp; values.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;But for more context:&lt;BR /&gt;I have a lookup :&lt;/P&gt;&lt;TABLE width="127px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class="multivalue selection-container"&gt;&lt;DIV class="real-text-wrapper"&gt;&lt;SPAN class="real-text"&gt;Code&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class="multivalue selection-container"&gt;&lt;DIV class="real-text-wrapper"&gt;&lt;SPAN class="real-text"&gt;Country&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;&lt;DIV class="multivalue selection-container"&gt;&lt;DIV class="real-text-wrapper"&gt;&lt;SPAN class="real-text"&gt;AT&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;TD width="87.0781px"&gt;&lt;DIV class="multivalue selection-container"&gt;&lt;DIV class="real-text-wrapper"&gt;&lt;SPAN class="real-text"&gt;Austria&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="40px"&gt;AU&lt;/TD&gt;&lt;TD width="87.0781px"&gt;&lt;DIV class="multivalue selection-container"&gt;&lt;DIV class="real-text-wrapper"&gt;&lt;SPAN class="real-text"&gt;Australia&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I need the Country column for display and the Code as value, because our other data uses only the code.&lt;/P&gt;&lt;P&gt;What i wanted to do is setting the multiselect to the 3 countries most relevant to us via JavaScript and i completely forgot i can just set the Initial value in xml&lt;/P&gt;</description>
      <pubDate>Mon, 11 Oct 2021 06:43:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/570418#M46868</guid>
      <dc:creator>puet</dc:creator>
      <dc:date>2021-10-11T06:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Set multiselect with JavaScript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/570432#M46875</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/238353"&gt;@puet&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can try below JS code to set multiselect input get selected with some values.&lt;/P&gt;&lt;P&gt;XML (Common for both js)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form script="a.js" theme="light"&amp;gt;
  &amp;lt;label&amp;gt;Abcd&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="multiselect" token="tkn_country" id="tkn_country"&amp;gt;
      &amp;lt;label&amp;gt;Country&amp;lt;/label&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;Country&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;Code&amp;lt;/fieldForValue&amp;gt;
      &amp;lt;search id="tkn_country_search"&amp;gt;
        &amp;lt;query&amp;gt;| makeresults | eval _raw="Code    Country
AT    Austria
AU    Australia"| multikv forceheader=1|table Code    Country&amp;lt;/query&amp;gt;
        &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
        &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
      &amp;lt;/search&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
&amp;lt;/form&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1) Select by value.&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!'
], function($, mvc) {
    var multi = mvc.Components.getInstance("tkn_country"); // your multiselect id here
    var defaultValues = ["AT", "AU"];
    multi.val(defaultValues)
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2) Select by label.&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!'
], function($, mvc) {
    var multi = mvc.Components.getInstance("tkn_country");
    var tkn_country_search = mvc.Components.getInstance("tkn_country_search"); // your multiselect id here
    var defaultValues = ["Austria", "Australia"];

    tkn_country_search.on("search:done", function() {
        var myResults = tkn_country_search.data("results"); // get the data from that search

        myResults.on("data", function() {
            resultArray = myResults.data().rows;
            val = [];
            $.each(resultArray, function(index, value) {
                if (jQuery.inArray(value[1], defaultValues) !== -1) {
                    val.push(value[0])
                }
            })
            multi.val(val)
        })
    })
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope both example will help you.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;▄︻̷̿┻̿═━一 &amp;nbsp; &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Oct 2021 08:53:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/570432#M46875</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2021-10-11T08:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: Set multiselect with JavaScript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/570590#M46891</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;I was missing the part where i get the value by its' Label.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; $.each(resultArray, function(index, value) {
                if (jQuery.inArray(value[1], defaultValues) !== -1) {
                    val.push(value[0])
                }
            })&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Works fine now.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Oct 2021 10:50:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Set-multiselect-with-JavaScript/m-p/570590#M46891</guid>
      <dc:creator>puet</dc:creator>
      <dc:date>2021-10-12T10:50:36Z</dc:date>
    </item>
  </channel>
</rss>

