Extracting email from a Survey response in brackets | XM Community
Skip to main content

For background, I have used qualtrics for several years and I can use workflow to send custom emails based on responses.  I am not a coder, but I am trying to learn basic syntax and functions. 

I am trying to do something that seems relatively simple and I am running into a problem.  I have several surveys that are sent via anonymous links, not emailed directly to people.  These surveys are designed to be accessed by anyone via a QR code on a flyer.  What I want the respondent to do is first select a name from a list of names, and I want that person that is selected to be sent an email upon survey completion.  Each name on the list is followed by their email address (for example John Doe <jdoe@madeupemail.com>).  I have tried the following: Create a new Embedded data element called RecipientEmail, then following a page break after the question run the following code on a hidden question: 

Qualtrics.SurveyEngine.addOnPageSubmit(function () {
  var extractedEmail = "${q://QID1/ChoiceGroup/SelectedChoices}".match(/<(.*?)>/);
  Qualtrics.SurveyEngine.setEmbeddedData('RecipientEmail', extractedEmail);
});

I then planned to query the RecipientEmail in the Workflow in the To: part of the email task.

But it does not work and I get a blank value.  If I run the code as:

Qualtrics.SurveyEngine.addOnPageSubmit(function () {
  var extractedEmail = "${q://QID1/ChoiceGroup/SelectedChoices}";
  Qualtrics.SurveyEngine.setEmbeddedData('RecipientEmail', extractedEmail);
});

I get the original text.  So I know everything is working except the .match function but after looking at countless examples and running a lot of permutations I don’t know what I’m doing wrong.  Thanks for any help you can give a novice.

Hi @EducatorNotProgrammer,

could you please provide more information which question type you are using? “Multiple choice” with “Allow one answer” setting? 

Furthermore, could you please explain why you do not let them enter their email themselves e.g. in a input? Please also think about data privacy when displaying personal data. 

Instead, you could also add all contacts with their email address and names in a mailing list and make use of the authenticator element: 

https://www.qualtrics.com/support/survey-platform/survey-module/survey-flow/advanced-elements/authenticator/authenticator-overview/

This will result in a start page like this: 

When the participant enters an email that is part of the mailing list, the survey can be continued and you can work with the embedded data from the mailing list. Just define it as I did in the example with “Email”. 

Best
Christian


Leave a Reply