Dashboards & Visualizations

Use seach results as JavaScript variable

duesser
Path Finder

I am running a search in JavaScript that returns results similar to this one.

 

new SearchManager({
	id: "my_search",
	results: true,
        search: `
            | makeresults count=10 
            | streamstats count
            | fields - _time
        `
});

 

What I would like to obtain is a JS array with the resulting vector in a variable. I tried to solve it like so:

 

let search = mvc.Components.get("my_search");
let results = search.data("results");

results_outside = results.on("data", function(){ // 1b)

	let rows = results.data().rows;

	let array = rows.flat(1); // I want the flattened array, no nested one

	console.log("array: ", array); 

    tokens.set("arrays", array); // 2)

	return array; // 1a)
});

console.log("results_outside: ", results_outside); 

 

 The `array` variable within the function has the desired results, as I can tell from the console. However exporting it to the global scope neighter works by:

 

1) storing it in `results_outside` - this will have the same value as results.

 

or

 

2) setting it to a token.

Labels (2)
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!

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...

Index This | How many sevens are there between 1 and 100?

August 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...