Dashboards & Visualizations
Highlighted

How to import the token value in the JavaScript in Simple XML?

Explorer

alt text
Create a wish come test.js code to get the value of $ time_ok1.earliest $.

0 Karma
Highlighted

Re: How to import the token value in the JavaScript in Simple XML?

Champion

In test.js, you need to require the right components, and then you can simply grab the tokens from the token model. Something like this:

 require([
     'splunkjs/mvc/simplexml/ready!',
     "splunkjs/mvc"
 ],
 function(
     mvc
     ) {
         // Get the default model
         var defaultTokenModel = splunkjs.mvc.Components.getInstance("default");
         // Get some token from there
         var token_kang = defaultTokenModel.get("kang");
         ...

See here for the docs. Be aware though that the object "tokenkang" at the moment contains two fields, and to get to the earliest in js, you need to do `tokenkang.earliest`.

0 Karma
Highlighted

Re: How to import the token value in the JavaScript in Simple XML?

Explorer

It appears to be undefined.

splunkjs.mvc.Components.getInstance ("default");

Will that be called justice in simplexml default?

0 Karma
Highlighted

Re: How to import the token value in the JavaScript in Simple XML?

Champion

What exactly is undefined?

0 Karma
Highlighted

Re: How to import the token value in the JavaScript in Simple XML?

Explorer
require(["splunkjs/ready!"], function(mvc) {
var deps = [
        "jquery",
        "splunkjs/ready!",      
        "splunkjs/mvc/searchmanager",
    ];
    require(deps, function(mvc) {               

    var defaultTokenModel = splunkjs.mvc.Components.getInstance("default");
    var token_def = defaultTokenModel.get("kang");

    alert(token_def);  << undefined
    console.log(token_def);
});
});
0 Karma
Highlighted

Re: How to import the token value in the JavaScript in Simple XML?

Champion

Oh, my bad. I mistook your id and token name. It has to be

var token_def = defaultTokenModel.get("time_ok1");

Sorry!

0 Karma
Highlighted

Re: How to import the token value in the JavaScript in Simple XML?

Explorer

You're welcome...

"time_ok1" Even if I value the results.
I think that haneunge "default" settings on the source code ... I do not know anything.

0 Karma
Highlighted

Re: How to import the token value in the JavaScript in Simple XML?

Champion

I'm sorry, I don't quite get what you're saying - is something still not working?

0 Karma
Highlighted

Re: How to import the token value in the JavaScript in Simple XML?

Explorer

Thank you.

Fixed with respect to this issue.

var tokens = mvc.Components.getInstance ("kang");
var defaultEtime = tokens.options.default.earliest_time;

0 Karma
Highlighted

Re: How to import the token value in the JavaScript in Simple XML?

Communicator

Hi this var tokendef = defaultTokenModel.get("timeok1");
Doesn't work for me. Any idea?

0 Karma