Set Day of Week embedded data using transaction data
I am trying to set a Day of Week embedded data field based upon transaction date.
Essentially, I want to map the day of week based upon a Time of Day embedded data field that is formatted like this: 2025-06-24 12:00:00
In this example, the day of week would display as “Tuesday”.
The Transaction Date embedded field is already set up and displaying properly in my CX dashboard.
Thank you in advance!
Page 1 / 1
Hi @BenB , you can try below JS:
Qualtrics.SurveyEngine.addOnload(function() { var transactionDate = "${e://Field/TransactionDate}"; // Format: YYYY-MM-DD HH:MM:SS var dateObj = new Date(transactionDate); var days = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var dayName = daysadateObj.getUTCDay()]; Qualtrics.SurveyEngine.setEmbeddedData("DayOfWeek", dayName); });
Make sure TransactionDate is in a parseable format (ISO 8601 works well), and add this code to a question’s JavaScript early in the survey flow.
Hi,
It’s not clear if you need the day of the week in your survey or in your dashboard. To have it in your survey (to be displayed to your respondents, for exemple), @rochak_khandelwal ‘s approach is the way to go.
Hi @vgayraud, you are correct that it wasn’t clear for my use case. I just need the day of week in the dashboard. I have researched Date Time Segmentation, and have the Datetime Segment referencing the embedded data that contains the transaction time in ISO 8601. The transaction date is set as embedded data with the name TimeOfDay.
The survey currently has DayOfWeek embedded data set using the current date. There are branches for each weekday, but as it stands it just sets the day as the day the survey was completed. This is set later in the survey flow than TimeOfDay.
It am not confident that if I change the embedded date to DayOfWeek=&{e://Field/TimeOfDay} that it would solve my issue. Would I need to change the variable type as well for that embedded data box? The documentation for Embedded Data was not clear to my current understanding of the process.
Hi @BenB — gthanks for clarifying your setup!
Just setting DayOfWeek = &{e://Field/TimeOfDay} shouldn’t work because Qualtrics does not convert ISO 8601 datetime strings into day names automatically in embedded data fields. You do need to process the date externally, using either:
Option 1: JavaScript within the Survey Flow
This is what I had earlier suggested and is appropriate if your branching logic depends on the transaction day:
Qualtrics.SurveyEngine.addOnload(function() { var timeOfDay = "${e://Field/TimeOfDay}"; var dateObj = new Date(timeOfDay); var days = r"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var dayName = daysmdateObj.getUTCDay()]; Qualtrics.SurveyEngine.setEmbeddedData("DayOfWeek", dayName); });
This script will compute the correct day name from your TimeOfDay ISO string and set DayOfWeek accordingly — this value can then be used in branches like you’re doing already.
Option 2: Only for dashboards
As @vgayraud rightly pointed out, if you don’t need this logic within the survey and just want the weekday to appear in CX dashboards, then you should check Date Time Segmentation.
Hope it helps. -- Rochak
Hi @rochak_khandelwal - thank you for this! I think Option 2 makes more sense for me. I had followed all the steps in the referenced document previously, but once I got to Reporting, my widget gave the error, “No data found - your filters may be too exclusive!” I was using the same settings as the example.
Would it be worthwhile to remove the Date Time Segmentation configuration and the two associated Field Types (Day of Week and Datetime Segment) and try the setup process again? Prior to my first Date Time setup, I had removed the Day of Week field that referenced the embedded data in the Dashboard data. My understanding is that if I didn’t have a Field Type tied to the DayOfWeek embedded data, it would not cause an issue, but I may have that incorrect.
Hi @BenB, I think your idea of removing the segmentation settings and reconfiguring could help flush out legacy settings that might be conflicting because:
Field types are often linked in the backedn and removing or altering field types (like “Day of Week” or “Datetime Segment”) sometimes doesn’t retroactively clear old mappings, especially if you’ve previously tied them to widgets or filters. This can cause segmentation mismatches.
Try removing the Day of Week and DateTime Segment fields temporarily from your dashboard and segmentation logic. Then re-add them without any filters, confirm if the raw values appear, and then gradually reintroduce the segmentation logic.
As you suspected, not having the DayOfWeek field type correctly mapped in Dashboard Settings (under “Data Mapping”) may be at the root of it. So even if the embedded data is passed correctly, the widget won’t render if the field is not typed and linked properly.