With information from the Qualtrics JavaScript Question API Class documentation (https://s.qualtrics.com/WRAPI/QuestionAPI/classes/Qualtrics%20JavaScript%20Question%20API.html#method_setEmbeddedData)
Reading and writing Qualtrics embedded data with JavaScript
Sometimes during a survey, one needs to read the value of some variable stored in the form of embedded data in a survey. This is often the case when one needs to manipulate the data and then write it back to the same (or another) embedded field.
JavaScript can read values from embedded data fields, and then the Qualtrics API has a method called setEmbeddedData() that writes any value into the selected embedded field.
In this example, I have a Qualtrics embedded field named "tickets". When participants see a certain part of my survey, I need to read the value of "tickets", add one to it, and then save the new value back to the embedded data.
First, I need to make sure to Set the Embedded Data in the Survey Flow
In the survey, go to click on "survey flow" and add a "Set Embedded Data" section. I'll create a field called "tickets"
JavaScript Code
Then, I will go to the question where I need to read and manipulate the embedded field, and click on add JavaScript
Qualtrics.SurveyEngine.addOnReady(function()
{
/* Get score from Qualtrics embedded field and parse (convert) it into a number*/
var numTickets = parseInt('${e://Field/tickets}');
/* Add one ticket */
numTickets = numTickets + 1;
/* Save new score to Qualtrics embedded field */
Qualtrics.SurveyEngine.setEmbeddedData('tickets', numTickets);
});