Replacing , with :: on more than 3 choices | XM Community
Skip to main content

Ran into a quandary. Can you help?

The Javascript is only concatenating the first few (3 to be exact) selections with "::" for multiple different fields. When more than 3 items are selected, there is no “::” only “,”

Example: Three or less selected:

  • PERFECT: City of Fishers::Community Physician Network::Community Physician Network - All::CPN Providers
  • NOT PERFECT (MORE THAN 3 SELECTED): ACO, Ambulatory Pharmacy, Analytics Associate Feedback, Infusion, Inpatient, Inpatient Psych - Fairbanks

Here is my code - any thoughts/what can I do to update this to capture more than 3 selections?:

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var string = '${q://QID5/ChoiceGroup/SelectedChoices}';
var new1=string.replace(/\\s*,\\s*/g, ",");
var replacestring= new1.replace(/,/g , '::');
console.log(replacestring)
console.log(new1)
Qualtrics.SurveyEngine.setEmbeddedData( 'Role', replacestring );

});


Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var string = '${q://QID50/ChoiceGroup/SelectedChoices}';
var new1=string.replace(/\\s*,\\s*/g, ",");
var replacestring= new1.replace(/,/g , '::');
console.log(replacestring)
console.log(new1)
Qualtrics.SurveyEngine.setEmbeddedData( 'Product Line', replacestring );

});


Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var string = '${q://QID62/ChoiceGroup/SelectedChoices}';
var new1=string.replace(/\\s*,\\s*/g, ",");
var replacestring= new1.replace(/,/g , '::');
console.log(replacestring)
console.log(new1)
Qualtrics.SurveyEngine.setEmbeddedData( 'Specialty/Region', replacestring );

});


Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var string = '${q://QID53/ChoiceGroup/SelectedChoices}';
var new1=string.replace(/\\s*,\\s*/g, ",");
var replacestring= new1.replace(/,/g , '::');
console.log(replacestring)
console.log(new1)
Qualtrics.SurveyEngine.setEmbeddedData( 'Sub-Specialty/Sub-Region', replacestring );

});
 

See example of what I am seeing.

First is “good” - but only up to 3 - second is “bad”.

How can I expand the first example to contain/work on more than 3?

 


Disregard this post! I identified the issue. The replace string does not work if an option is “ ’s” is selected - such as “Women’s”. So this really isn’t a numbers issue, but a “ ‘s” issue. I eliminated the ‘s - and the code worked!


Leave a Reply