I wish to use the setChoiceValueByVariableName API function with a question of type Text Entry - Form variant.
This function should be called as `setChoiceValueByVariableName(variableName, [subId], value)` where `variableName` is a string described as "The variable name of the choice(s) being set" in the documentation.
In the SE engine, I used to replace `variableName` with the text that appears on the left of the text field in the form.
With the new JFE engine, these lines of code no longer work (no error message, the text fields are simply no longer populated).
Does anyone know what the variableName parameter should contain when using this API function?
this.setChoiceValueByVariableName("byVariableName", "Modified answer"); // Does not work
this.setChoiceValue(2, "Modified answer"); // Works
Results in:
!
Page 1 / 1
As a follow up on my own question, querying the content of the `VariableName` field from within the `Qualtrics.SurveyEngine.QuestionInfo` object shows that it contains the choice's number in string format, not the content of the `Text` field.
So this function seems to have become useless, as one needs to know the number that was affected to the choice in any case.
Unless one writes custom code to fetch the number associated with a given Text field. If anyone has already done this, I would appreciate sharing such code.
So this function seems to have become useless, as one needs to know the number that was affected to the choice in any case.
Unless one writes custom code to fetch the number associated with a given Text field. If anyone has already done this, I would appreciate sharing such code.
Do you still need help with this issue? If so could you clarify for me a bit more what it is exactly you are trying to accomplish?
And what about sending your variables to the embedded data fields and then accessing them using piped text?
Piped text is not appropriate in my case because the question is inside a Loop & Merge block. The same variable gets reused several times within a survey run.
Here is what I ended up doing:
```
var questionChoices = Object.values(qualtricsQuestion.getQuestionInfo().Choices);
var variableName = questionChoices.find(x => x.Text === text).VariableName;
qualtricsQuestion.setChoiceValueByVariableName(variableName, value);
```
`qualtricsQuestion` is the reference of the question I want to edit with javascript.
`text` contains the descriptive text for the target input field inside this question. In the case from my initial screenshot, this would contain "byVariableName".
`value` contains the value I want to record in this field.
Here is what I ended up doing:
```
var questionChoices = Object.values(qualtricsQuestion.getQuestionInfo().Choices);
var variableName = questionChoices.find(x => x.Text === text).VariableName;
qualtricsQuestion.setChoiceValueByVariableName(variableName, value);
```
`qualtricsQuestion` is the reference of the question I want to edit with javascript.
`text` contains the descriptive text for the target input field inside this question. In the case from my initial screenshot, this would contain "byVariableName".
`value` contains the value I want to record in this field.
> @GhisLabo said:
> Piped text is not appropriate in my case because the question is inside a Loop & Merge block. The same variable gets reused several times within a survey run.
Generally, this does not matter. The embedded fields are updated after each loop. Therefore you can use piped containing an embedded field. It will always contain the information generated in the previous loop. Here you can find how to set any text (including the piped one) as a default choice in the text entry box.
I have tried following simple code and it worked.
Qualtrics.SurveyEngine.addOnload(function()
{
var questionText = "${lm://Field/1}";
var n = "${e://Field/n}"+ questionText;
Qualtrics.SurveyEngine.setEmbeddedData("n", n);
});
In case this won't help you to solve your problem, I recommend you to
> clarify a bit more what it is exactly you are trying to accomplish
as @RDurant said.
> Piped text is not appropriate in my case because the question is inside a Loop & Merge block. The same variable gets reused several times within a survey run.
Generally, this does not matter. The embedded fields are updated after each loop. Therefore you can use piped containing an embedded field. It will always contain the information generated in the previous loop. Here you can find how to set any text (including the piped one) as a default choice in the text entry box.
I have tried following simple code and it worked.
Qualtrics.SurveyEngine.addOnload(function()
{
var questionText = "${lm://Field/1}";
var n = "${e://Field/n}"+ questionText;
Qualtrics.SurveyEngine.setEmbeddedData("n", n);
});
In case this won't help you to solve your problem, I recommend you to
> clarify a bit more what it is exactly you are trying to accomplish
as @RDurant said.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.