Retreaving Embedded Data using Javascript | XM Community
Skip to main content

I’m trying to retrieve an embedded value that I set from using a block of web service to query from a site using javascript. But I keep running into an error. 

Namely, I’m trying to use javascript to assign that value to a constant. Let’s say my embedded data field is named “__js_MyData” in the web service block. I tried doing:

  1. const data = “${e://Field/__js_MyData}”;
  2. const data = Qualtrics.SurveyEngine.getJSEmbeddedData('MyData');

But while the 1st approach gives me an error that says there is a syntax error, the 2nd approach just has the value data undefined.

I’m sure the embedded data is stored, since if I just use piped text in my questions, it displays the right content. 

Has anyone tried to do this before? Is there a way to do this?

 

Hi @CindyJ. I did not get 100% how you define your embedded data. However, just defined some embedded data in the flow for test purpose: 

 Define some JavaScript for the 1st question in the examplary block: 

Qualtrics.SurveyEngine.addOnload(function() {
var embeddedDataValue = "${e://Field/__js_MyData}";
console.log("Embedded Data Value: " + embeddedDataValue);
});

Which resulted in the embedded data value being shown in the console which means it was successfully stored to the variable: 

Maybe provide more context on your exact setup. Could be an issue if the embedded data is defined in the same block as where you want to read it. 

Best
Christian


Hi @CindyJ. I did not get 100% how you define your embedded data. However, just defined some embedded data in the flow for test purpose: 

 Define some JavaScript for the 1st question in the examplary block: 

Qualtrics.SurveyEngine.addOnload(function() {
var embeddedDataValue = "${e://Field/__js_MyData}";
console.log("Embedded Data Value: " + embeddedDataValue);
});

Which resulted in the embedded data value being shown in the console which means it was successfully stored to the variable: 

Maybe provide more context on your exact setup. Could be an issue if the embedded data is defined in the same block as where you want to read it. 

Best
Christian

Thank you so much!! 


Leave a Reply