Dashboards & Visualizations

HTML Dashboard: How to use Javascript to change text input?


I have trouble in using JS to change my text input from a comma list to convert search to a list of " OR ...OR" statement.
So if my input text is "1,2,3,4", then my query after converting should look like: sourcetype=mydata id=1 OR id=2 OR id=3 OR id=4 | .....;
However, when I inspect the query in search box, it is showing:
sourcetype=mydata id=1,2,3,4. Does anyone has anyidea? Following is my code
var ids = new String("$myTextValue$");
ids = ids.replace( " ","" );
ids = ids.split( "," );

    var ids_str = [];
    for( var i = 0; i < ids.length; i++ )
      ids_str.push( "id=" + ids[i] );

    var newComputedValue = ids_str.join( " OR " );

    var search1qry = "sourcetype=mydata " + newComputedValue ;

    var search1 = new SearchManager({
        "id": "search1",
        "earliest_time": "$earliest$",
        "cancelOnUnload": true,
        "search": search1qry,
        "status_buckets": 0,
        "latest_time": "$latest$",
        "app": utils.getCurrentApp(),
        "auto_cancel": 90,
        "preview": true
    }, {tokens: true, tokenNamespace: "submitted"});


In this context,I don't see the point of using javascript...
Indeed I guess you could transform the token value simply from you Simple XML dashboard code !
You just need to add :

replace("$myTextValue$", ",", " OR ")
inside your input ...

However maybe I didn't get your context properly ...

0 Karma

Path Finder

The problem with this code is in this part:

var ids = new String("$myTextValue$");

When i do :
var ids = new String("1,2,3,4");
then i get an object which is not string. It's because I'm doing a string object out of a string object which is wrong approach - http://stackoverflow.com/questions/5750656/whats-the-point-of-new-stringx-in-javascript for reference.

So instead of doing this try just:
var ids = $myTextValue$;

0 Karma

Path Finder

have you solved this issue? i and trying to do the same thing. thanks in advance!

0 Karma
Get Updates on the Splunk Community!

Don't wait! Accept the Mission Possible: Splunk Adoption Challenge Now and Win ...

Attention everyone! We have exciting news to share! We are recruiting new members for the Mission Possible: ...

Unify Your SecOps with Splunk Mission Control

In today’s post, I'm excited to share some recent Splunk Mission Control innovations. With Splunk Mission ...

Data Preparation Made Easy: SPL2 for Edge Processor

By now, you may have heard the exciting news that Edge Processor, the easy-to-use Splunk data preparation tool ...