Email Trigger Piped Multiple Choice Formatting | XM Community
Skip to main content
Solved

Email Trigger Piped Multiple Choice Formatting

  • September 12, 2023
  • 10 replies
  • 95 views

Forum|alt.badge.img+1

Hi All:

 

Hoping to get some advice on whether formatting on a multiple choice question is possible.

After piping out the multiple choice text in a email trigger, the choices appear on a single line.

 

For example:

 

[ ] Workshop 1, Aug 1, 2023

[x] Workshop 2, Aug 2, 2023

[x] Workshop 3, Aug 3, 2023

[ ] Workshop 4, Aug 4, 2023

[x] Workshop 5, Aug 5, 2023

 

Would be piped in the email trigger as:

Workshop 2, Aug 2, 2023, Workshop 3, Aug 3, 2023, Workshop 5, Aug 5, 2023

 

What I was hoping to do is to have:

Workshop 2, Aug 2, 2023

Workshop 3, Aug 3, 2023

Workshop 5, Aug 5, 2023

 

Any guidance would be appreciated.

 

 

Best answer by TomG

Use JS to modify the piped string and save it as an embedded data field that you can pipe into your email:

var pipedAnswers = "${q://...}".replace(/, /g,"<br>");
Qualtrics.SurveyEngine.setEmbeddedData("pipedAnswers",pipedAnswers);

 

10 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • Answer
  • September 12, 2023

Use JS to modify the piped string and save it as an embedded data field that you can pipe into your email:

var pipedAnswers = "${q://...}".replace(/, /g,"<br>");
Qualtrics.SurveyEngine.setEmbeddedData("pipedAnswers",pipedAnswers);

 


Forum|alt.badge.img+1
  • Author
  • 5 replies
  • September 12, 2023

Thanks @TomG !

 

Do you know how I would pipe the variable into the email template?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • September 12, 2023

Thanks @TomG !

 

Do you know how I would pipe the variable into the email template?

In the example I gave, it would be ${e://Field/pipedAnswers}


Forum|alt.badge.img+1
  • Author
  • 5 replies
  • September 12, 2023

I’m getting a blank string when I console log the pipedAnswer.

 

For “${q://...}” do I need to replace the “...” with the question id?  Is there a way to determine what that is?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • September 12, 2023

Yes, you need to replace ${q://...} with the actual piped string that contains your question’s selected choices. You also need to put the code inside an appropriate function such as Qualtrics.SurveyEngine.addOnload(). 


Forum|alt.badge.img+1
  • Author
  • 5 replies
  • September 12, 2023

When i try to do something like this:

jQuery("#"+this.questionId+" .InputText")

 

I get the following error:

SE API Error: TypeError: jQuery(...).replace is not a function


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • September 12, 2023

When i try to do something like this:

jQuery("#"+this.questionId+" .InputText")

 

I get the following error:

SE API Error: TypeError: jQuery(...).replace is not a function

You’ve tried to use replace on a jQuery object instead of a string.  This seems unrelated to your original question since the jQuery command would be for a text entry field.


Forum|alt.badge.img+1
  • Author
  • 5 replies
  • September 12, 2023

I see what you mean.

 

This is what I ended up with, but still getting an empty string:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {

var pipedAnswers = "${q://QID1/ChoiceGroup/SelectedChoices}".replace(/, /g,"<br>");

Qualtrics.SurveyEngine.setEmbeddedData("pipedAnswers",pipedAnswers);

    console.log("pipedAnswers",pipedAnswers)

});

 

In my email trigger I have:

${e://Field/pipedAnswers}


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • September 12, 2023

That script can’t be on the same page as QID1 (the pipe of QID1 would be empty).


Forum|alt.badge.img+1
  • Author
  • 5 replies
  • September 12, 2023

Thanks for the help @TomG !  Worked like a charm!