Dashboards & Visualizations

How Do I Update Url With Search Tokens in HTML Dashboard

SplunkPersonal
Path Finder

Hello Everyone,

I have an HTML Dashboard. On it I have a SearchManager, a TimeRangeView, and a number of DropdownViews and TextInputViews that modify MVC Tokens that are used in the search query. The search updates properly when any of these are changed. If I manually add the token names to the dashboard url, I can load a page where those tokens are pre-populated.

However when any token values are changed when the user interacts with the TimeRangeView/DropdownViews/TextInputViews and the search runs, the url remains the same as when I loaded the page. What is the proper way to update the URL when the search executes so that a user can copy the url and perform that search at a later time with those token values?

Thank you very much for any help you can provide.

Tags (2)
0 Karma
1 Solution

SplunkPersonal
Path Finder

Since I did not receive a reply, I'm assuming there is not a built-in way to handle this via Splunk. I ended up implementing this capability myself by building the new url with my token values (using encodeURIComponent for encoding) and then using history.pushState/history.replaceState to update the actual url without leaving the page. Splunk already parses those tokens out of the url when a user returns to that url later.

Ideally I'd love to see this capability directly integrated into the Splunk token model (allowing user to specify which tokens they want to update in the url and whether they want pushState-type or replaceState-type browser history support).

View solution in original post

paramagurukarth
Builder

Are you updating your tokens via JavaScript. Because normally splunk update the URL If you use internal splunk inputs..
If you are using JavaScript to Update token.. Please update URL token (Submitted Tokens) as well..

var defaultTokens = mvc.Components.get("default"); 
var submittedTokens = mvc.Components.get("submitted"); 
var tokens = {
    get: function(tokenName) {
        return defaultTokens.get(tokenName);
    },

    set: function(tokenName, tokenValue) {
        defaultTokens.set(tokenName, tokenValue);
        submittedTokens.set(tokenName, tokenValue);
    }, 
    on: function(eventName, callback) { 
        defaultTokens.on(eventName, callback); 
    }
};

And do token.get()/set()
Check "Working with tokens in a custom component" here

SplunkPersonal
Path Finder

Since I did not receive a reply, I'm assuming there is not a built-in way to handle this via Splunk. I ended up implementing this capability myself by building the new url with my token values (using encodeURIComponent for encoding) and then using history.pushState/history.replaceState to update the actual url without leaving the page. Splunk already parses those tokens out of the url when a user returns to that url later.

Ideally I'd love to see this capability directly integrated into the Splunk token model (allowing user to specify which tokens they want to update in the url and whether they want pushState-type or replaceState-type browser history support).

phoenix_down
Path Finder

I'm looking for a solution to the same issue. I actually do have a Submit button, which when pressed does update the URL. However, I'd like for users to not have to go through this extra step. Do you mind sharing your code for your solution?

0 Karma

p_gurav
Champion

Do you have submit button also?

0 Karma

SplunkPersonal
Path Finder

Thanks for the reply. I do not have a submit button on the dashboard. I have the SearchManager set to update the search automatically when the tokens change.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...