Embedded data within a block | XM Community
Skip to main content

Is it possible to calculate embedded data inside a block (rather than after it) and use it for display logic for subsequent questions in the same block?

I have a block of questions, some of which are used to calculate a score in the format of embedded data. However, the embedded data is only calculated after the block is completed, as seen in ‘Survey Flow’. I would like to use this embedded data within that block to direct participants to different subsequent questions (from the same block) depending on their score.

But the ‘Survey flow’ section allows to insert embedded data only between blocks, not inside them.

Does this mean I need to split my block into several blocks, with the embedded data calculated in between them?

Any advice will be appreciated. Thank you.

Use JS to calucate the embedded data value and store it in respective embedded data.


Hello @kubato ,

You may want to consider the following steps:

  1. Arrange all required Embedded Variables at the top. Introduce a new variable (e.g. 'Score') and link your calculated 'Score' to that variable.
  2. Position your Question Block beneath the variables. (Note: Include in this block only the questions necessary for calculating the score.)
  3. Add a Branch and set the condition as "If Score = 1." Include a block with the subsequent questions you wish to display for this particular score.
  4. Introduce another Branch and set the condition as "If Score = 2." Add a block with subsequent questions for this specific score.
  5. Repeat steps 3 and 4 for all scores and their corresponding subsequent questions.

Please let me know if this method aligns with your requirements.


Use JS to calucate the embedded data value and store it in respective embedded data.

Thank you, that worked!

I created an empty embedded variable called ‘PHQ9TotalScore’ just before that session in the survey flow, and then used JS to update it as soon as the repective answers are collected. I could then use thios embedded data for logic in subsequent questions in the same session.

Here is my script (which I added to the question following question ‘phq9’):

 

Qualtrics.SurveyEngine.addOnload(function()

{

    var phq1 = "${q://QID715/SelectedChoicesRecode}";

    var phq2 = "${q://QID716/SelectedChoicesRecode}";

    var phq3 = "${q://QID717/SelectedChoicesRecode}";

    var phq4 = "${q://QID718/SelectedChoicesRecode}";

    var phq5 = "${q://QID719/SelectedChoicesRecode}";

    var phq6 = "${q://QID720/SelectedChoicesRecode}";

    var phq7 = "${q://QID721/SelectedChoicesRecode}";

    var phq8 = "${q://QID722/SelectedChoicesRecode}";

    var phq9 = "${q://QID723/SelectedChoicesRecode}";

    

    var PHQ9TotalScore = parseInt(phq1) + parseInt(phq2) + parseInt(phq3) + parseInt(phq4) + parseInt(phq5) + parseInt(phq6) + parseInt(phq7) + parseInt(phq8) + parseInt(phq9);

    

    Qualtrics.SurveyEngine.setEmbeddedData('PHQ9TotalScore', PHQ9TotalScore);

});

Qualtrics.SurveyEngine.addOnReady(function()

{

    /*Place your JavaScript here to run when the page is fully displayed*/

});

Qualtrics.SurveyEngine.addOnUnload(function()

{

    /*Place your JavaScript here to run when the page is unloaded*/

});

 


Please note that the best answer is from @rondev.

I clicked the other one by mistake and unfortunatelly cannot change it:


“according to our guidelines, once a "Best Answer" has been selected it cannot be changed. Please ensure to carefully consider your choice before making it final.”

 


Hello @kubato ,

You may want to consider the following steps:

  1. Arrange all required Embedded Variables at the top. Introduce a new variable (e.g. 'Score') and link your calculated 'Score' to that variable.
  2. Position your Question Block beneath the variables. (Note: Include in this block only the questions necessary for calculating the score.)
  3. Add a Branch and set the condition as "If Score = 1." Include a block with the subsequent questions you wish to display for this particular score.
  4. Introduce another Branch and set the condition as "If Score = 2." Add a block with subsequent questions for this specific score.
  5. Repeat steps 3 and 4 for all scores and their corresponding subsequent questions.

Please let me know if this method aligns with your requirements.

Thank you. In the end I used JS to do it, but your point 1 was still very helpful for it!


Leave a Reply