Convert imported file into an array accessed in JavaScript code block | XM Community
Skip to main content
Solved

Convert imported file into an array accessed in JavaScript code block

  • June 5, 2018
  • 1 reply
  • 15 views

Forum|alt.badge.img+3
Has anyone been able to take an imported file (e.g., a list of contacts for distribution), convert a single field (e.g., email address) into an array that can then be used as part of a JavaScript code block within a single question? Thanks in advance for any help.

Best answer by mattyb513

Yeah, this is pretty simple. In the contact list, concatenate the items in the field with something that isn't normally used, like a `~` or `;`: `email1@test.com~email2@test.com~email3@test.com` Then in the JS editor, get the field: `var customEmails = Qualtrics.SurveyEngine.getEmbeddedData('custom_emails');` Now split it into an array: `var customEmailsArr = customEmails.split('~');` Note that you may need to include the embedded data field in your survey flow for it to be accessible.

1 reply

mattyb513
Level 4 ●●●●
Forum|alt.badge.img+6
  • Level 4 ●●●●
  • 163 replies
  • Answer
  • July 27, 2018
Yeah, this is pretty simple. In the contact list, concatenate the items in the field with something that isn't normally used, like a `~` or `;`: `email1@test.com~email2@test.com~email3@test.com` Then in the JS editor, get the field: `var customEmails = Qualtrics.SurveyEngine.getEmbeddedData('custom_emails');` Now split it into an array: `var customEmailsArr = customEmails.split('~');` Note that you may need to include the embedded data field in your survey flow for it to be accessible.