Qualtrics Javascript timeout behaving unpredictably | XM Community
Skip to main content

**TLDR Main issue:** The same JS code has been replicated over multiple blocks of qualtrics to time out each block within 35 minutes. But, in one of of 10 implementions, one of the blocks is randomly  getting timed out too soon. And it is never happening in the first block.

**Details:** I am using Qualtrics blocks that should time out in 35 minutes, I have an embedded variable called "limit" that is set at 35 minutes (2100000ms). 
Each block has multiple loops (using a feature called loop-and-merge). The first question of the first loop of every block defines the start-time for the block:

Part 1:


```
    

    
    let loop_count = parseInt("${lm://CurrentLoopNumber}");

    if (loop_count === 1) {
        var starttime = new Date().getTime();
        Qualtrics.SurveyEngine.setEmbeddedData('start', Number(starttime)); 

        Qualtrics.SurveyEngine.setEmbeddedData('time_so_far', Number(0)); 
```
        


Part 2: Next, the main questions of each block contain the following JS code to keep track of the time spent so far, and times out the page when the limit is reached. I use a display condition to ensure that none of the following pages within that block is shown any longer.

```

    var endtime = new Date().getTime();
    var endtime = Number(endtime);
    var starttime = Number(Qualtrics.SurveyEngine.getEmbeddedData('start')); 
    var time_so_far = (endtime - starttime); 
    //alert("time_so_far = " + time_so_far);
    var limit = Number(Qualtrics.SurveyEngine.getEmbeddedData('limit')); 
    
    Qualtrics.SurveyEngine.setEmbeddedData("time_so_far", time_so_far); 
     
    let loop_count = parseInt("${lm://CurrentLoopNumber}");
    Qualtrics.SurveyEngine.setEmbeddedData("loop_count", loop_count); 
    
    //The setInterval() method calls a function at specified intervals (in milliseconds). The setInterval()         method continues calling the function until clearInterval() is called, or the window is closed.
    
    setTimeout(function() {
    let time_so_far = limit+1;
    Qualtrics.SurveyEngine.setEmbeddedData("time_so_far", time_so_far);     
    jQuery("#NextButton").click();
    }, limit + 1000 - time_so_far);
```
    
Any help would be hugely appreciated. (I tried posting on Qualtrics forum, but somehow I do not have the rights to make a new post!)

Be the first to reply!

Leave a Reply