Splunk Search

dropdown via js search splunk

anissabnk
Path Finder

Hello,

I need your help for something.

I want to get a dropdown via using a result from a search with using js.
 
 
I want the dropdown to take the search result: index=_internal |stats count by source |table source
 
Thank you so much
 
 
Labels (1)
Tags (4)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@anissabnk 

Are you looking for this?

XML:

<dashboard version="1.1" script="dropdown_via_js.js">
  <label>Dropdown Via JS</label>
  <row>
    <panel>
      <html>
        <div id="mydropdownview"></div>
      </html>
    </panel>
  </row>
</dashboard>

 

JS:

require([
    "splunkjs/mvc/searchmanager",
    "splunkjs/mvc/dropdownview",
    "splunkjs/mvc/simplexml/ready!"
], function(SearchManager, DropdownView) {

    // Use this search to populate the dropdown with index values
    let my_search = new SearchManager({
        id: "example-search",
        search: "index=_internal |stats count by source |table source" 
    });

    // Instantiate components
    let my_dropdown = new DropdownView({
        id: "example-dropdown",
        managerid: "example-search",
        labelField: "source",
        valueField: "source",
        el: $("#mydropdownview")
    }).render();

});

 

Screenshot 2024-07-10 at 10.34.15 AM.png

 

I hope this will help you.

Thanks
KV
An upvote would be appreciated if any of my replies help you solve the problem or gain knowledge.

 

 

Tags (2)
0 Karma

anissabnk
Path Finder

@kamlesh_vaghela, can you help me please ? 😉

0 Karma

anissabnk
Path Finder

No that's not it. I want my dropdown to be powered by a search but which will be defined in a js.

 

Something like this?

anissabnk_0-1720515487571.png

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

I'm not sure I understand the question - where is the JS coming from?

Are you saying you want to create a list of dropdown choices from the result of that search

If so, simply set your input to be

    <input type="dropdown" token="your_token" searchWhenChanged="true">
      <label>Example Dropdown from search</label>
      <fieldForLabel>source</fieldForLabel>
      <fieldForValue>source</fieldForValue>
      <search>
        <query>index=_internal |stats count by source</query>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </search>
    </input>
0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...