Setting Embedded Variable - When back button is ON! | XM Community

Setting Embedded Variable - When back button is ON!

  • 26 April 2021
  • 8 replies
  • 7 views

Greetings,
We have a particular requirement i.e. setting embedded variables in live survey with back button ON! Having said this, when the respondent is moving back and forth in the link, embedded variable should hold revised value in it. Have tried this in one of the demo survey, since have limited access to client QSF.
Example: Considering having 10 questions starting from Q1 to Q10. Based on the response provided, I saw Q1, Q3, Q5, Q6, Q7, Q8 and Q10 in the link. At Q10, I decided to go back till Q5.
·      On Q8, post clicking back button, all my embedded variables which are associated to Q8 only will be set to blank.
·      So still while going back, embedded variables associated with Q7 and Q6 will be also set to blank.
·      Now after I update my responses at Q5, so the embedded variables associated to this question will be also updated accordingly – post clicking ‘next’ button.
Block Name to be referred: Block 3 - Method 3
Attached QSF and Block which needs your insights whether this approach can work across all surveys and question types (which are covered)
CustomCode.qsf.
Thanks in advance!
Jigar


8 replies

Userlevel 7
Badge +30

Hi jigar_g ,
I would recommend reaching out to Qualtrics support for consultation on this. They'll have the best understanding of the back end behavior and know if this requirement is possible.

Userlevel 2
Badge +3

Hi jigar_g ,
There's nothing strange happening here. Your code starts by

  1. setting JS variables to 0,

  2. [If clicking NEXT only] updates JS variables with values from question

  3. Sets ED fields equal to your JS variables

If I'm moving backwards in the survey, step #2 does not happen, but steps #1 and #3 will still happen thus overwriting the ED fields to 0.
Here is the code snippet on Q15 where I am witnessing this:
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{

  var ED_Q15_1 = 0;
var ED_Q15_2 = 0;
var ED_Q15_3 = 0;
var Sum = 0;

if(type == "next")// if type is back, this is not entered
{

if(this.getChoiceValue(1) == null){ED_Q15_1 = 0}else{ED_Q15_1 = this.getChoiceValue(1)}
if(this.getChoiceValue(2) == null){ED_Q15_2 = 0}else{ED_Q15_2 = this.getChoiceValue(2)};
if(this.getChoiceValue(3) == null){ED_Q15_3 = 0}else{ED_Q15_3 = this.getChoiceValue(3)};


}


// if type is back, these fields are just 0 and thus the ED fields ae overwritten to 0
Qualtrics.SurveyEngine.setEmbeddedData("ED_Q15_1",ED_Q15_1);
Qualtrics.SurveyEngine.setEmbeddedData("ED_Q15_2",ED_Q15_2);
Qualtrics.SurveyEngine.setEmbeddedData("ED_Q15_3",ED_Q15_3);

console.log("/////////////////////////////////////////////ED_Q15///////////////////////////////////////////////////");
console.log("ED_Q15_1 :"+Qualtrics.SurveyEngine.getEmbeddedData("ED_Q15_1"));
console.log("ED_Q15_2 :"+Qualtrics.SurveyEngine.getEmbeddedData("ED_Q15_2"));
console.log("ED_Q15_3 :"+Qualtrics.SurveyEngine.getEmbeddedData("ED_Q15_3"));

if(type == "next")
{
var ED_Q14 = Qualtrics.SurveyEngine.getEmbeddedData("ED_Q14_1")
var ED_Q15 = Qualtrics.SurveyEngine.getEmbeddedData("ED_Q15_1")
var Sum = ED_Q14 + ED_Q15
}



Qualtrics.SurveyEngine.setEmbeddedData("Sum",Sum)
console.log("Sum :"+Qualtrics.SurveyEngine.getEmbeddedData("Sum"));

});

Hi MatthewM - Landed here after Qualtrics Support itself mentioned to post this over here.

Hi farmaly : Thank you for looking into this. That's good to know. 😀
On the other hand, wanted to know whether did you get chance to have a glance at remaining piece of code in that block for other question types?

Userlevel 2
Badge +3

jigar_g
I pointed out what was wrong in this question: that you've created an IF block "next"
The same issue likely exists with the rest of your questions. I recommend you go through them yourself and identify where and why you've wrapped code in an IF block.

Hi faris : So by default onsubmit block works for both 'back' and 'next' button. and we wanted certain piece of code to execute only when 'next' button is clicked.

Userlevel 2
Badge +3

I understand that jigar_g
You said, "Having said this, when the respondent is moving back and forth in the link, embedded variable should hold revised value in it."
The explanation is that the code wrapped that you've placed in an IF block doesn't run when you go BACK and thus the ED values are cleared.


Yes faris it will clear ED values while going back, because we never know if that question will not show up who has ED variables associated in it, then those ED should hold original values which are storing.

Leave a Reply