Tidy up an embedded field using regex and then update | XM Community
Question

Tidy up an embedded field using regex and then update

  • 14 July 2020
  • 0 replies
  • 24 views

Userlevel 5
Badge +11

Hi All,

I have created a survey with multiple questions. I then concatenate the selections made in these multiple choices separated by a |. Some answers may not be answered and so I'd like to tidy up the double instance of the | and then pass this back to the embedded field to then be used in say a CX dashboard where I can define the delimeter. I've not tested whether have multiple delimeters with no data (empty arrays) might upset the qualtrics widgets so I thought it would be easy to use some simple regex to conver it.

Below is the formula I'm using in a survey flow to concatenate the fields together.
${q://QID37/ChoiceGroup/SelectedChoices}|${q://QID39/ChoiceGroup/SelectedChoices}|${q://QID41/ChoiceGroup/SelectedChoices}|${q://QID43/ChoiceGroup/SelectedChoices}|${q://QID45/ChoiceGroup/SelectedChoices}|${q://QID47/ChoiceGroup/SelectedChoices}|${q://QID49/ChoiceGroup/SelectedChoices}|${q://QID50/ChoiceGroup/SelectedChoices}

Exporting the data into excel (see pic below) you can see the way the code looks ('Team|||Hi||||Health & Safety') and using some simple regex: '[|]{2,}' replace with '|', you can ensure that only one | is in between everything else giving you: ('Team|Hi|Health & Safety'). Nice huh?! 😃 However, please could you help me work out how to use regex with javascript / qualtrics as I'm unsure how you do this. I found some pages getting the value of a field into a JS variable but my problem is using regex (I'm assuming JS does have regex) and then uploading the change back into the survey flow so to speak). I've read some people have had issues updating the value so would be keen to know what issues I may experience along the way.

Thanks

Rod Pestell
image.png


0 replies

Be the first to reply!

Leave a Reply