setEmbeddedData not recording selection until click back into the question | XM Community
Question

setEmbeddedData not recording selection until click back into the question

  • 18 September 2019
  • 3 replies
  • 11 views

Userlevel 5
Badge +11
Hi All,

I've observed a very strange issue. I have a Like / Dislike question where the user answer the survey can select a choice for either. The following question then asks the reasons for whatever the liked or disliked. This question is not forced and so the user can just select an choice for like but doesn't have to select an item for dislike. This means I need to use some display logic. Currently I've got a very static display logic which works through all the different possible choices. It works but it's not very robust should you change the options in the like / dislike question. So I thought I'd use some javascript.

In the survey flow I've created two fields: 'Q3.5_Like_text' and 'Q3.5_Dislike_text'.

This is a screen shot of the survey

!


In the question I've used this code:

<code>
Qualtrics.SurveyEngine.addOnload(function()
{

});

Qualtrics.SurveyEngine.addOnReady(function()
{
var1 = "${q://QID15/ChoiceGroup/SelectedChoicesForAnswer/1}";
var2 = "${q://QID15/ChoiceGroup/SelectedChoicesForAnswer/2}";
console.log(var1);
console.log(var2);
Qualtrics.SurveyEngine.setEmbeddedData( 'Q3.5_Like_text', var1)
Qualtrics.SurveyEngine.setEmbeddedData( 'Q3.5_Dislike_text', var2)

});

Qualtrics.SurveyEngine.addOnUnload(function()
{

});
</code>
Are there any silly syntax's I've left out?! eg. I've not put a semi colon at the end of every line.


I have inserted a text question following this to check that the embedded fields are being updated, however I'm finding that they are updating to a null figure at first, and not the choice I've selected. It's not until I click the 'Back' button and then 'Next' that the embedded fields are being populated.

These are the choices
!

Click next, you get null values
!

Click back and then next, the embedded fields are then populated
!

Please could someone help me resolve this issue? I've tried a matrix question and this has the same issue.

Another option I suppose is to split the block and use the survey flow method to populate the embedded field but I was hoping that this java script method would work.

Thanks in advance

Rod Pestell

3 replies

Userlevel 7
Badge +11
> @Rod_Pestell said:
> Another option I suppose is to split the block and use the survey flow method to populate the embedded field but I was hoping that this javascript method would work.

Since I am not very strong with Javascript, that is what I would suggest. Barring that, have you tried moving your code to 'On Load'?
Userlevel 5
Badge +11
Hi JenCX, thanks for the reply, my notifications aren't working so sorry for the delay. I've tried onload but I get the same issue. It looks like there is another layer of scripting going on that we don't know about and it doesn't complete until next block. This sounds very familiar as I had the same issue when using the Table of Content (TOC). Questions woudn't be marked completed until you moved to the next block meaning for each section you had to have at least 2 blocks per section but then the TOC showed both blocks up! I had to write some java script to hide the blocks we didn't want showing. The script works but for a split second you see the items in the TOC which you don't want to see - so it's a little clunky again.
Userlevel 3
Badge +9
In my experience you can only set embedded data on page submission, not onready or onload. That's why the embedded data is blank until they click back/next.

Try setting the embedded data before they arrive to the page (onSubmit on the previous page). That should fix your problem.

Leave a Reply