Intermittent bug - Qualtrics.SurveyEngine.addOnload being called twice on the survey page for a Java | XM Community
Question

Intermittent bug - Qualtrics.SurveyEngine.addOnload being called twice on the survey page for a Java

  • 24 March 2021
  • 3 replies
  • 137 views


The issue is how the Qualtrics runtime is calling / interacting with our custom code. Documentation (https://www.qualtrics.com/support/survey-platform/survey-module/question-options/add-javascript/) states that "addOnload() – Executed when the page is loaded." and in my understanding this should execute only once for a javascript question loaded (and this is what happens mostly.
However, we are seeing a bug, by qualtrics - that addOnload() function is being called in the middle of the question and we lose all our variables. More interestingly, we are observing the issue on Windows browsers - Firefox and Chrome and we did not experience this issue on MacOS.
We have an old version of survey which uses less memory and it works fine; we are seeing the issue with the newer version after our memory usage has increased. This may be one of the causes, but I am not sure.
The issue looks similar to an old issue once discussed on stackoverflow: https://stackoverflow.com/questions/29159984/qualtrics-surveyengine-addonload-runs-twice-in-preview-mode-in-qualtrics-survey But I guess now the runtime mechanisms are different and the solution also does not apply.


3 replies

Screen Shot 2021-04-13 at 10.57.54 AM.pngSo I guess there is a limit in their system, which restricts field values to be less than 20,000 characters. We were saving some data store dump and hit this limit. We never saw this error before, but started seeing it recently.

Userlevel 7
Badge +21

They mention this limit on their support pages. Read here. For storing more data, you can look at embedded data fields, however, they have also started acting weird lately, search the forums for issues.

Userlevel 3
Badge +10

I'm not sure if this applies in your rase - I noticed that you're getting a validation error.
addOnload() is called again when you trigger a validation error. As far as I know this behavior is not documented, but you can create a minimal reprex by setting a MC question's text to a random number (generated in Javascript) in addOnload(), set to forced response, and when you run the survey click next without responding to the MC. You'll see that the random number changes each time you press next and the validation fails. This is probably not your issue, because you say that it only happens in certain browsers. But, it might be related, in that addOnload can be called more than once if the page is reloaded in some way.
If this is the issue, you can do some fancy things like increment an embedded variable using the loop and merge loop number, and check in your addOnload code if the embedded variable code has already been incremented.

Leave a Reply