Solved
JavaScript code doesn't execute properly
Hello there,
on the last page of my survey, I do some JS calculations (getting answer values, doing calculations and setting embedded fields). The code in the last question (which only exists so I can execute JS code there) doesn't work properly. It seems to only work when I access/load the last page/question multiple (2 or 3) times by using the table of contents element.
I suspect my issue is similar to this (order of execution): https://www.qualtrics.com/community/discussion/199/using-javascript-with-embedded-data-and-or-selected-choices
However, my code is executed on a (last) separate block, page and question, so I don't know why it's not working.
Also I added some console.log elements so that I can track the code and according to the chrome dev console, it seems that the code is being executed twice, with two different VM IDs (all my debug.log(whatever) are showing twice).
Why is it being executed twice there?
Why do I have to load the page/question multiple times to get my question to work?
How can I get my code to execute only once and then work properly?
Thanks for any help!
Best answer by CanerLC
I found the problem.
Basically what was going wrong was that I tried to access/get some embedded data values which I also set in the very same code block.
I couldn't get some of the values during initial execution, because they were being set at the same time, hence the inconsistency
My solution is luckily very easy, because I can substitute the embedded data references with proper variable references, since I am initializing the variables during the first part of the calculations.
I should have better used them further down the line(s) again instead of embedded data fields.
View originalLeave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.