Hi,
I have a dashboard in html code with one search query which provides the result in Single Numeric Value.
Is there any way that I can take the result of my search in some variable?
I want to display it in a JavaScript alert popup i.e. alert("my search result is: " + search_result_var)
.
Which variable in html code of dashboard stores the search result.
Please Help..!!!
Hi i am new to splunk, can you please give me a sample code which i can use?
One way to achieve this is put a listener on your search and then assign the value to a token. For instance if my single panel was using search1 and the token I wanted to set was "user".
var tokens = mvc.Components.getInstance("default");
var singleresult=splunkjs.mvc.Components.get("search1");
singleresult.data("results").on("data", function(results) {
var username = results._data['rows'][0][0];
tokens.set("user",username);
});
You could then use that token or variable anywhere in your HTML. You can use it in a search as any other token by calling it with $user$ or in your script by the variable alert("my search result is: " + username)
. If you're not using the alert inside the listener, you can retrieve the token value and set it as a variable anywhere else by -
var desiredvariable=tokens.get("user");
@Flynt[Splunk]
Thanks for your help! 🙂
Have you tried assigning the value to a input token and call it ? might work. I had a same single value panel...i created a token and assigned the single value and then called the token like
value is : $single_value$
and it displays just fine.Hope this helps!
Thanks,
Raghav
Thank you so much!! It was really helpful 🙂