Hi, We are new to this and my question is probably very basic. We are using moment.js to calculate a time period based on a user's response. The browser console.log shows that moment.js is calculating the days correctly, but we are not able to access the data that we set. How do we call these dates that we set as embedded variables in subsequent blocks as piped text in a question? It this not possible? I don't think we have successfully called up an embedded variable that we set with javascript so I think there is something that we are not understanding.
We would like a subsequent question later in the survey to include the earliestDay and latestDay variables in the question.
var daysAgoo = "${q://QID47/ChoiceGroup/SelectedChoices}";
var today = moment();
var monthFromToday = moment(today).add(1, 'months');
var targetDate = moment(monthFromToday).subtract(daysAgoo, 'days');
var earliestDay = moment(targetDate).subtract(6, 'days');
var latestDay = moment(targetDate).add(6, 'days');
targetDate= moment(targetDate).format('LL');
earliestDay= moment(earliestDay).format('LL');
latestDay= moment(latestDay).format('LL');
Qualtrics.SurveyEngine.setEmbeddedData('targetDate ', targetDate );
Qualtrics.SurveyEngine.setEmbeddedData('earliestDay', earliestDay);
Qualtrics.SurveyEngine.setEmbeddedData('latestDay', latestDay);
console.log(targetDate);
console.log(earliestDay);
console.log(latestDay);
Page 1 / 1
Did you already define your variables in an Embedded Data element in your survey flow? If not, then you need to use .addEmbeddedData instead of .setEmbeddedData. Once you do that, you should be able to reference them normally using ${e://Field/variablename}.
I have also always used double quotes (instead of single) around the embedded data variable name when adding/setting, but I'm not sure if that matters or not.
Thank yo so much! i think that is what we were doing wrong. We didn't define the variables first.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.