Using javascript in a loop & merge decision tree type of procedure | XM Community
Skip to main content

Hi!
I need to create a procedure, that has a series of questions regarding a certaing decision, which is to be made by the participant.
Essentialy it is a question about a certain amount, that the person can agree, or disagree to pay.
If he or she disagrees, she is directed to a question which has a lower sum in the place of the previous one, and the participant is given the choice again. If the participant agreed, the procedure looks the same, but the sum changes to a higher one.
Now, I need this to occur 7 times for each person (meaning 7 separate questions).
I created the first one, that determines the path as a separate block. The following questions are placed in a block, that has two paths in it: the addition and the subtraction one.
I put them both in a loop, which looks like this:
image.pngwith the names in the fields representing the values which are to be added, or removed.
The tricky part comes now: if a participant clicks yes on the first three questions, but later clicks no, then the appropriate amount has to be subtracted from the sum that is displayed to him.
I figure that it has to be done using some sort of javascript way, but I have no clue how to operate something like that.
Does anybody have a clue on how to do it?

As what it seems, I believe, you need the score of all the questions combined and need to add/subtract based on what they select on these 7 questions. I would suggest you to create an embedded variable and fetch and set the variable using both math operation and get/setEmbeddedData function to set the appropriate values.
Let me know if you need any further help!


Leave a Reply