set embedded data from this.questionId SelectedChoicesRecode | XM Community
Skip to main content
Hi Qualtrics Community!



I am trying to use javascript to write a value to embedded data based on the current questions Recoded Values. I know how to do this if the QuestionID is known, but I don't know how to string the code toegether to refer to this.questionId (I'd like to use the same javascript for a large number of questions without modifying it to refer to the specific question IDs).



The functionality I am looking for is essentially "If this.questionId's SelectedChoicesRecode = 1 then set embedded data "c" = 1, else "c" = 0.



Any pointers are appreciated!

G2000
Hi @G2000,

here you can find how to get the actual selected answer.

Then you can use the following command to store anything in an embedded field. Don't forget to define your embedded field in the survey flow.

`Qualtrics.SurveyEngine.setEmbeddedData( 'embeddedDataVariable', value );`
Thanks @fleb!

This definitely worked. Only downside is that this grabs the response number, not Recoded Value (and I am not knowledgeable enough to adjust that). But I can make that work in this case!

Thanks again!

G2000
> @G2000 said:

> Thanks @fleb!

> This definitely worked. Only downside is that this grabs the response number, not Recoded Value (and I am not knowledgeable enough to adjust that). But I can make that work in this case!

> Thanks again!

> G2000

This will give you what you want:

```

Qualtrics.SurveyEngine.addOnPageSubmit(function() {

var selectedRecode = this.getChoiceRecodeValue(this.getSelectedChoices());

var c = (selectedRecode == "1") ? 1 : 0;

Qualtrics.SurveyEngine.setEmbeddedData("c", c);

});

```
@TomG - Thank you - that's excellent!

Leave a Reply