I have a list of unique codes set as embedded data, and I would need to verify whether the answer to the first question matches any code in this list. It seems qualtrics does not do "exact match". That is, suppose the embedded data is called "codeList", and i set it to = ABA2, ABC3, then when I enter "A" in the first question, it is considered a "match" because A is part of the list. How to make qualtrics to do exact match? !
Page 1 / 1
I would solve it with javascript:
Qualtrics.SurveyEngine.addOnload(function()
{
var codeList = "${e://Field/codeList}"; //Gets your code list
var code = "${q://QID172807697/ChoiceGroup/SelectedChoices}"; //Gets your code
codeList = codeList.split(","); //Your code list was one string; this split it to elements
var included = codeList.includes(code); //Returns true if the code is in the code list or noting
Qualtrics.SurveyEngine.setEmbeddedData( "included", included ); //Send "included" to an embedded field of the same name
});
Note: the embedded field "included" must be defined in the survey flow.
Note2: originally I used single parentheses instead of double ones, but I'm not able to send the post including singe ones.
Qualtrics.SurveyEngine.addOnload(function()
{
var codeList = "${e://Field/codeList}"; //Gets your code list
var code = "${q://QID172807697/ChoiceGroup/SelectedChoices}"; //Gets your code
codeList = codeList.split(","); //Your code list was one string; this split it to elements
var included = codeList.includes(code); //Returns true if the code is in the code list or noting
Qualtrics.SurveyEngine.setEmbeddedData( "included", included ); //Send "included" to an embedded field of the same name
});
Note: the embedded field "included" must be defined in the survey flow.
Note2: originally I used single parentheses instead of double ones, but I'm not able to send the post including singe ones.
hi fleb,
thanks so much for helping out! I tested the code but there are some problems I cannot fix. Here is the javascript i used:
Qualtrics.SurveyEngine.addOnload(function()
{
var codeList = "${e://Field/codeList}"; //Gets your code list
var code = "${q://QID1/ChoiceTextEntryValue}"; //Gets your code
codeList = codeList.split(","); //Your code list was one string; this split it to elements
var included = codeList.includes(code); //Returns true if the code is in the code list or noting
Qualtrics.SurveyEngine.setEmbeddedData( "included", included ); //Send "included" to an embedded field of the same name
});
I defined codeList and included as embedded data as the first step. but it seems the value of "included" is empty if I do it this way:
!
if I define the codeList and included after the default block, the returned value for "included" is always true (I get this by downloading the data).
Would you be able to tell me what I am doing wrong? Much appreciated!
thanks so much for helping out! I tested the code but there are some problems I cannot fix. Here is the javascript i used:
Qualtrics.SurveyEngine.addOnload(function()
{
var codeList = "${e://Field/codeList}"; //Gets your code list
var code = "${q://QID1/ChoiceTextEntryValue}"; //Gets your code
codeList = codeList.split(","); //Your code list was one string; this split it to elements
var included = codeList.includes(code); //Returns true if the code is in the code list or noting
Qualtrics.SurveyEngine.setEmbeddedData( "included", included ); //Send "included" to an embedded field of the same name
});
I defined codeList and included as embedded data as the first step. but it seems the value of "included" is empty if I do it this way:
!
if I define the codeList and included after the default block, the returned value for "included" is always true (I get this by downloading the data).
Would you be able to tell me what I am doing wrong? Much appreciated!
Hi @yzhang6,
where exactly is your Javascript? I supposed that it isn't at QID1 or in the same block since you had code defined as an embedded field in your original example. If so, would it be possible to move the code to a question from another block or you need to evaluate the code right at the beginning?
If this is not the case, try to alert variables one by one (e.g.: add `alert(code)` below `var code = "${q://QID1/ChoiceTextEntryValue}";`). This will show you where exactly is the problem.
where exactly is your Javascript? I supposed that it isn't at QID1 or in the same block since you had code defined as an embedded field in your original example. If so, would it be possible to move the code to a question from another block or you need to evaluate the code right at the beginning?
If this is not the case, try to alert variables one by one (e.g.: add `alert(code)` below `var code = "${q://QID1/ChoiceTextEntryValue}";`). This will show you where exactly is the problem.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.