Dashboards & Visualizations

Help with multi-select input needed - save own variants

damucka
Builder

Hello,

I was wondering if this is feasible to have a multiselect input in the dashboars, which would allow to save down the chosen values as a user-variant and reuse it next time.

Example would be a list of SIDs (system IDs) in a monitoring dashboard, let us say around 20, which the user has to analyse. After choosing them in the first multiselect the user should get the possibility to save the selection under his own variant name, which would be offered next time he starts the dashboard.

Has anyone did anything similar?

Kind Regards,

Kamil  

Labels (1)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@damucka 

You can achieve by using cookie.  Can you please try this?

<form script="a.js">
  <label>MultiSelect with Cookie</label>
  <fieldset submitButton="false">
    <input type="multiselect" token="tkn_numbers" id="tkn_numbers_id">
      <label>Numbers</label>
      <fieldForLabel>a</fieldForLabel>
      <fieldForValue>a</fieldForValue>
      <search>
        <query>|makeresults count=10 | eval a=1 | accum a</query>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </search>
    </input>
  </fieldset>
</form>

 

require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc) {

    var submittedTokenModel = mvc.Components.get("submitted");
    var defaultTokenModel = mvc.Components.get('default');

    var current = Splunk.util.getConfigValue("USERNAME");

    function setsrcCookie(cookiename, cookievalue) {
        document.cookie = current + "_" + cookiename + "=" + cookievalue;
        console.log(document.cookie)
    }

    function getsrcCookie(cookiename) {
        var nameEQ = current + "_" + cookiename + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0)
                return c.substring(nameEQ.length, c.length);
        }
        return null;
    }
    submittedTokenModel.on("change:tkn_numbers", function() {
        var form_tkn_numbers = submittedTokenModel.get('form.tkn_numbers');
        setsrcCookie("tkn_numbers_cookie", form_tkn_numbers.join('| '));
    });

    var tkn_numbers_cookie = getsrcCookie("tkn_numbers_cookie");
    console.log("tkn_numbers_cookie", tkn_numbers_cookie.split("| "))
    defaultTokenModel.set("form.tkn_numbers", tkn_numbers_cookie.split("| "));
    submittedTokenModel.set(defaultTokenModel.toJSON());

});

 

Thanks
KV
▄︻̷̿┻̿═━一   😉

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

0 Karma

damucka
Builder

@kamlesh_vaghela 

Thank you.

However I am not sure if I understand how this should work:

- With the code below I got a multiselect field with the 1 - 10 numbers to choose. I also copied the a.js to the ../etc/apps/MYAPP/appserver/static. But somehow I do not see the chosen values to be filled in again when I refresh / restart the form. 

Am I missing anything?

Kind Regards,

Kamil

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@damucka 

Can  you please share your sample code?

KV

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

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

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...