Search code examples
javascripttypescriptqualtrics

How to parseInt or ParseInt embedded data with TypeScript in Qualtrics?


Even when I save an integer to embedded data earlier in the survey flow (in previous blocks on different screens), I am not able in Javascript to get the embedded data value, ensure it is parsed as a number/integer, then use it in a loop. Is this something about TypeScript? I didn't see anything about parseInt or ParseInt in the TypeScript documentation.

For example, suppose I do the following:

// Draw a random number
var x = Math.floor(Math.random() * 5);

// Save it in embedded data
Qualtrics.SurveyEngine.setEmbeddedData("foo", x);

// In a later block on a different screen, get the embedded data as an integer
var x_new = "${e://Field/foo}"; // not an int
var x_new = parseInt("${e://Field/foo}"); // doesn't work
var x_new = ParseInt("${e://Field/foo}"); // doesn't work

// Loop using x_new:
for(i = 0; i < x_new; i++) {
   console.log(i)
   }

Any idea why this isn't working? Perhaps I just don't know how to parseint().


Solution

  • In "normal" JS runtime system, we have parseInt function, the function gets a string (like number string) as a parameter. In this env, we don't support your syntax - "${e://Field/foo}", because it is not a "number string".

    In Qualtrics system environment they have parseInt too, but they support their custom syntax "${e://Field/foo}" to get EmbeddedData.

    Make sure that your code is running on Qualtrics system environment.