set embedded data from this.questionId SelectedChoicesRecode | XM Community
Solved

set embedded data from this.questionId SelectedChoicesRecode

  • 7 March 2019
  • 4 replies
  • 149 views

Userlevel 1
Badge +6
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
icon

Best answer by TomG 8 March 2019, 07:12

View original

4 replies

Userlevel 5
Badge +6
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 );`
Userlevel 1
Badge +6
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
Userlevel 7
Badge +27
> @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);
});
```
Userlevel 1
Badge +6
@TomG - Thank you - that's excellent!

Leave a Reply