Dashboards & Visualizations

Splunk Query using startSearch() is not running in a loop with token


I have a splunk query(with javascript) which i would like to run multiple times using javascript loop. Please find below code

dupcount1.data("results").on("data", function(results) {

if (DupData == true) {
    var dupcount = results._data['rows'][0][0];
    var i;
    var batchsize = 10
    for (i = 0; i <= dupcount / batchsize; i++) {

        if (i == 0) {
            defaultTokenModel.set("head1", batchsize);


        } else {
            defaultTokenModel.set("head2", batchsize * (i + 1));
            defaultTokenModel.set("tail", batchsize * i);



    return true;


based on value of i i am setting token and start search. when (i==0) the search runs fine and everything completes graciously. Issue i am facing is when (i !=0) than only for last loop job is triggered. what i would like is that , if there are 9 loops, 9 searches should be triggered. i am not able to understand why only last search is starting in else loop.

Thanks in advance.

0 Karma


Probably something wrong with the instantiation / initialization of search9, as opposed to search4 which is working.

Since you didn't show us that portion of the code, we aren't going to be able to tell you exactly what you did wrong, unless search9 is a typo. If search9 is a typo, then you should also check the line with search8.

0 Karma


HI @DalJeanis

Thanks for replying. i will clear out the air here.

  • I am using a for loop and where variable i decides the batch size
  • inside loop there is if condition, if satified one condition it starts search4, till now everythings work great.
  • In else Condition, i am triggering start search9 where the value of variable i is being used to set a token used in search
  • so for e.g
  1. if value of i =1 , i am setting token value token1=400 and token2= 200 and triggering search using startSearch().
  2. if value of i =2 , i am setting token value token1=600 and token2=400 and riggering search using startSearch(). and so on till loop is valid.
  • now ideally in else loop, if there are 3 values of i there should be 3 instances of token and search JOB, instead i always and only get last instance of search9.

please let me know if you need more explainations.


0 Karma
Get Updates on the Splunk Community!

SplunkTrust | Where Are They Now - Michael Uschmann

The Background Five years ago, Splunk published several videos showcasing members of the SplunkTrust to share ...

Admin Your Splunk Cloud, Your Way

Join us to maximize different techniques to best tune Splunk Cloud. In this Tech Enablement, you will get ...

Cloud Platform | Discontinuing support for TLS version 1.0 and 1.1

Overview Transport Layer Security (TLS) is a security communications protocol that lets two computers, ...