Set embedded data in page based on constant sum question | XM Community
Skip to main content

I would like to set the total sum of a constant sum question (Q2) to an embedded data field. Then use the embedded data field in display logic for Q3. Q1 is a text entry box.
Display Q3 if TotalsumQ2 < Q1Answer
I can't set embedded data in the survey flow like described here because I am using a table of contents.
I put this JS on Q2 but it is inconsistent:
Qualtrics.SurveyEngine.addOnUnload(function()
{
Qualtrics.SurveyEngine.setEmbeddedData( 'totalkidscurrentyear', "${q://QID16/TotalSum}" );
});
I looked at this too but it is for multiple choice questions and I am not sure how to convert it to be for a constant sum question.
Can anyone help?

Hi mbrown ,
What do you men when you say "JS on Q2 but it is inconsistent:", does it work sometimes ?
Ideally it should not work based on my understanding as the pipedtext values are updated after page submit.

If i would have to do the same i would take the value in the textbox(for constant sum) using JS once next is clicked and then set this in am embedded data.
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{

    if(type == "next")
    {    
        Qualtrics.SurveyEngine.setEmbeddedData("totalkidscurrentyear",$("QID4_Total").value)
    }
});


Thanks for your response NiC.
I put this code on QID 16
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{


    if(type == "next")
    {    
        Qualtrics.SurveyEngine.setEmbeddedData("totalkidscurrentyear", "${q://QID16/TotalSum}")
    }
});
But it doesn't set the value to the embedded data field. I have to put it on the constant sum question in order to use the embedded data field in display logic in the next question, correct?
Is the embedded data field set before the next question begins to be loaded?


Hi mbrown,
So the response for Q16(i.e.constant sum questions) is saved after the response is submitted. and the code runs as the response is being saved so the piped text answers won't work.

you will need to get the value from text box directly


Leave a Reply