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!

Customer Experience | Splunk 2024: New Onboarding Resources

In 2023, we were routinely reminded that the digital world is ever-evolving and susceptible to new ...

Celebrate CX Day with Splunk: Take our interactive quiz, join our LinkedIn Live ...

Today and every day, Splunk celebrates the importance of customer experience throughout our product, ...

How to Get Started with Splunk Data Management Pipeline Builders (Edge Processor & ...

If you want to gain full control over your growing data volumes, check out Splunk’s Data Management pipeline ...