Extracting day of the week and month name as embedded data from answer | XM Community
Skip to main content
Solved

Extracting day of the week and month name as embedded data from answer

  • April 19, 2024
  • 3 replies
  • 150 views

SandraH
Level 3 ●●●
Forum|alt.badge.img+14

I have a question in a survey asking the date of the class. I have the default choice as today ${date://CurrentDate/SL} How can I create an embedded data field for the Day of the Week and Month name from this response?

Best answer by vgayraud

Hi @SandraH ,

Create 2 EDs in your survey flow named selectedDay and selectedMonth and add this code to your question.

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{

const date = new Date(jQuery("#"+this.questionId+" .InputText").val());
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
Qualtrics.SurveyEngine.setEmbeddedData('selectedDay', days[date.getDay()]);
Qualtrics.SurveyEngine.setEmbeddedData('selectedMonth', months[date.getMonth()]);

});

 

View original

3 replies

vgayraud
QPN Level 5 ●●●●●
Forum|alt.badge.img+48
  • QPN Level 5 ●●●●●
  • 373 replies
  • Answer
  • April 19, 2024

Hi @SandraH ,

Create 2 EDs in your survey flow named selectedDay and selectedMonth and add this code to your question.

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{

const date = new Date(jQuery("#"+this.questionId+" .InputText").val());
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
Qualtrics.SurveyEngine.setEmbeddedData('selectedDay', days[date.getDay()]);
Qualtrics.SurveyEngine.setEmbeddedData('selectedMonth', months[date.getMonth()]);

});

 


SandraH
Level 3 ●●●
Forum|alt.badge.img+14
  • Author
  • Level 3 ●●●
  • 15 replies
  • April 19, 2024

Thank you so much!


Forum|alt.badge.img+1

@vgayraud i tried using this script but didnt work for me. 


Leave a Reply