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!

Streamline Data Ingestion With Deployment Server Essentials

REGISTER NOW!Every day the list of sources Admins are responsible for gets bigger and bigger, often making the ...

Remediate Threats Faster and Simplify Investigations With Splunk Enterprise Security ...

REGISTER NOW!Join us for a Tech Talk around our latest release of Splunk Enterprise Security 7.2! We’ll walk ...

Introduction to Splunk AI

WATCH NOWHow are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. ...