Dashboards & Visualizations

How to set token value in the updateView using Javascript?

rsathish47
Contributor

Hi all ,

Can you please help me how to set token value in the updateView? I have added my code.

I know that am missing something , please help me

// demoview 
define(function(require, exports, module){
    // Base class for custom views
    var SimpleSplunkView = require('splunkjs/mvc/simplesplunkview');
    var mvc = require("splunkjs/mvc");

// Define the custom view class
var DemoView = SimpleSplunkView.extend({
    className: "demoview",

    // Change the value of the "data" property
    options: {
        data: "results"
    },

    // Override this method to configure your view
    // This function must return a handle to the view, which is then passed
    // to the updateView method as the first argument. Because there is no
    // visualization, just return 'this'
    createView: function() {
        return this;
    },

    // Override this method to put the Splunk data into the view
    updateView: function(viz, data) {
        // Print the data object to the console
        console.log("The data object: ", data);

         var tokens = mvc.Components.get("default");

// Retrieve the value of a token $mytoken$
var tokenValue = tokens.get("token1");

console.log("Aready existsS" + tokenValue);
// Change the value of a token $mytoken$
tokens.set("token1", "this is the new value");

        //var tokens = mvc.Components.getInstance("default");
        //tokens.set("token1", "Test");
        console.log("Current -->" + tokens.get("token1"));
        var myResults = data[0];  // Sets this to the first (and only) row
        this.$el.html("The count of search results: <b>" + myResults + "</b>");
    }
});

return DemoView;
});

Thanks

Tags (2)
0 Karma
1 Solution

rsathish47
Contributor

it is fixed by adding form.tokenname..

tokens.set("form.token1", "this is the new value")

View solution in original post

rsathish47
Contributor

it is fixed by adding form.tokenname..

tokens.set("form.token1", "this is the new value")

Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

New Release | Splunk Cloud Platform 10.1.2507

Hello Splunk Community!We are thrilled to announce the General Availability of Splunk Cloud Platform 10.1.2507 ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

&#x1f5e3; You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...