How To Set The Order Of Iterations Within a Loop

Overview

This How-To will explain and show how you can set the order of iterations within a given loop chapter in a few simple steps:

  1. Step 1: Add the needed Call-Back function to the ‘Advanced Scripts’
  2. Step 2: Add the relevant code to the Call-Back function in order to perform your logical script.

Step 1: Add the needed Call-Back function to the ‘Advanced Scripts’

Add the following code to your advanced script’s box:
function OnCreateIterationOrder(inChapterIndex, inIterationOrder)

{

}

This function is called, behind the scenes, in the first time a chapter is entered (while conducting a survey).
the 1st parameter, ‘inChapterIndex’ passes through the current chapters index that the surveyor is located, for example:

And the 2nd parameter, ‘inIterationOrder’ passes through the original iteration order of the loop, for example:
If chapter 1 is a loop that iterates 5 times, it will pass through: [1,2,3,4,5].

Step 2: Add the relevant code to the Call-Back function in order to perform your logical script.

Configure your function to suit your logical scripts.
Lets say for example, that we have 2 chapters and chapter 2 is a loop that iterates 5 times according to an answer scale.
We want chapter two to iterate in the order [2,1,3,4,5], if Q1 (for example, a question in chapter 1) answer is equal to 2, we can write something like this:

function OnCreateIterationOrder(inChapterIndex, inIterationOrder)

{

    if(inChapterIndex==2)

    {

        if(Answer(1)==2)

        {

            return [2,1,3,4,5];

        }

        else

        {

            return inIterationOrder;

        }

    }

}

* this should be written in the function we wrote in Step 1, within the advanced scripts box, as following:

Basically, what I wrote is:
** If I am in chapter index 2 -> check if the answer of Q1 is 2
    -> if it is answer 2 -> set the iteration order to be [2,1,3,4,5];
    elsewhere (Answer is not 2) -> set the iteration order to be the original one.
**

You can write any script that you wish in order set different loop iterations order with this method.

That’s it!

Was this article helpful?
4 out of 5 found this helpful
Have more questions? Submit a request

Comments

3 comments
  • Great insight! The only problem I see is that you have to check, whether ChapterIndex is the same before go to live. It will not be updated automatically, right?

    I guess there is a way to refer to ChapterIndex by its name?

  • I use that programming but have a problem if you back is not updated the inIterationOrder and stays with the first one that is generated.

    how i can do to update the inIterationOrder ?

    cuestion id 388c7d0c-6584-4801-b34d-eafa55b66b5a
    Qref(4) and chapter(2)

    regards

  • Hi Adolfo,

    At the moment that is how the mechanism is structured (once the random order of iterations is set it will be used for all the occasions where this loop chapter is executed).

    We have a road map development task to enable the re-ordering of the execution in different execution occasions.

    Regards,
    Daniel

Please sign in to leave a comment.