Dashboards & Visualizations

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

benjaminlin1019
Explorer

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"});

gdiogo
Explorer

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

piUek
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

paulstark
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!

Exciting News: The AppDynamics Community Joins Splunk!

Hello Splunkers,   I’d like to introduce myself—I’m Ryan, the former AppDynamics Community Manager, and I’m ...

The All New Performance Insights for Splunk

Splunk gives you amazing tools to analyze system data and make business-critical decisions, react to issues, ...

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...