I do not understand why this simple script doesn't work. Makes logical sense; doesn't work.
Here's the code:
`Qualtrics.SurveyEngine.addOnload(function()
{
var SurveyYear = Qualtrics.SurveyEngine.getEmbeddedData("SurveyYear");
// Convert from EmbData String to Int
SurveyYear = parseInt(SurveyYear);
// Calculate Year after SurveyYear
var NextYear = SurveyYear + 1;
// Convert back to String to set NextYear EmbData
NextYear = NextYear.toString();
Qualtrics.SurveyEngine.setEmbeddedData("NextYear", NextYear);
});`
I'm trying to use variables to set the Survey Year instead of hard-coding the year, which is common practice here at my shop. I want to have my users pass in the current survey year when they upload their contacts panel. My EmbeddedData field is named SurveyYear, which will this year equal 2019. I use JavaScript (which I'll eventually put in a <script> tag in my Header) to do the math to add 1 to the year to the SurveyYear, set the result to NextYear, and write that back to a blank EmbeddedData field which I've created in the Survey Flow, but not declared a value.
The only line that doesn't work is the Qualtrics.SurveyEngine.setEmbeddedData("NextYear", NextYear);.
I've tried using these combinations:
- this.setEmbeddedData("NextYear", NextYear)
- Qualtrics.SurveyEngine.setEmbeddedData("NextYear", "2020")
- Qualtrics.SurveyEngine.setEmbeddedData("NextYear", 2020)
- Tried function in addOnload, addOnReady
What am I missing? Does setEmbeddedData not work on the jfe platform? Thanks for any info you can give.
-Jeremy
Best answer by TomG
View original