How do I take the response from a multi-select multiple choice question into a variable to reformat the response as a string separated with pipe symbol "|" instead of commas?
you can use JS and replace “,” with “|” symbol. or you can use embedded field to store the selection one by one. for e.g. if Q1 is MS question and embedded field is abc. so you can use branch logic as if 1 is selected in Q1, then abc = ${e://Field/abc} | Q1 select answer, same you can do for every option one by one.
Arun, Thank you for your response. With the embedded field option, there is an extra | at the end of the last choice. Wonder if there is any other technique to avoid that?
Yes, you can pull that embedded responses data in your JS code and can remove the last | if no element after that and can also remove first pipe of no element is available.
below are two methods
array.shift(); // Removes the first element from an array and returns only that element.
array.pop(); // Removes the last element from an array and returns only that element.
Suppose your embedded field name “Multidata”. You can create another embedded field called as “Multidata1”. Since you must have created one block for Q1 and applied punching in embedded field under survey flow and then created another block for next questions Q2 etc. So you can paste below code in Q2 JS notepad. then can check the data of new embedded field “Multidata1”.
var arrx='${e://Field/Multidata}';
var arr=arrx.split('|');
setTimeout(function(){
if(arr.length > 0 && arr 0]==""){
arr.shift();
}
if(arr.length > 0 && arr arr.length-1]==""){
arr.pop();
}
Qualtrics.SurveyEngine.setEmbeddedData( 'Multidata1', "arr" );
},30);
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.