Setting embedded data to a maximum | XM Community
Skip to main content

New to JS/not very experienced in qualtrics and struggling to figure this out. Respondents answer a question regarding a likelihood (i.e., enter a number from 0 to 100) and I want to ask them how confident they are that the right answer is between their answer +/- 5%. I can compute these values with embedded data, e.g.,

Up_10yr_plus5=$e{ ${q://QID4/ChoiceTextEntryValue} + 5}.

My problem is if someone answers, for example, 97, I would like the variable up_10yr_plus5 to be 100 rather than 102 (97+5).

From what I’ve read, it seems I need to use javascript (as math functions in embedded data are limited) to write something like:

Qualtrics.SurveyEngine.addOnload(function()
{
    var max = Math.max("${e://Field/Up_10yr_plus5}",100);
Qualtrics.SurveyEngine.setEmbeddedData("max", max);

});

 

I thought that this would create a new embedded variable called max that I could then insert in my question. Yet, when I select insert piped text, embedded data field, Up_10yr_plus5 shows up but max does not.

Any guidance would be appreciated.

 

Hi @rjmissionbeach ,

 

Alternatively, you can consider creating two branch logic that checks the respondent’s input and create the embedded data based on the input in the survey flow.

For example,

input is less than 95, Up_10yr_plus5=$e{ ${q://QID4/ChoiceTextEntryValue} + 5}.

input is 95 or more, Up_10yr_plus5=100.

 


Thank you @Chee Heng_SZ - that worked great!


Leave a Reply