Parse embedded data first/last name | XM Community
Skip to main content
Question

Parse embedded data first/last name

  • June 18, 2024
  • 2 replies
  • 115 views

Forum|alt.badge.img

Is it possible to split an embedded data field into 2 fields? I currently combine multiple text entry fields (due to branching logic) into an embedded data field that is a respondent’s full name, named “Research Panel Contact Name”. At this point, I don’t want to edit the survey to create a new question within the survey.

 

This embedded data is set within the survey flow.

I’d like to be able to parse the embedded data field at the first space in the text so that I have a first name and a last name field.

 

Is there an easy custom code to do this?

 

Thanks,

Todd

2 replies

KWigg
Level 2 ●●
Forum|alt.badge.img+9
  • Level 2 ●●
  • November 26, 2025

Not sure if you resolved this, but it’s difficult to tell from the screenshot what you’re trying to accomplish.


arunxmarchitect
Level 2 ●●
Forum|alt.badge.img+3

@KWigg ​@toddbarnett,

Just adding some clarity around how to split a full name stored in Embedded Data into first name and last name in Qualtrics.

If your survey flow already captures a full name (e.g. field_full_name), Qualtrics doesn't automatically break it into separate fields. To do that, you’ll need a small JavaScript snippet added to a question that appears immediately after the Embedded Data has been set in the survey flow.

In my example, the Embedded Data fields are:

  • field_full_name

  • field_first_name

  • field_last_name

Goal: Split the full name by space and store the values into first and last name fields.

 

Steps

Step 1: Add the necessary Embedded Data fields in the Survey Flow
(e.g. field_full_name, field_first_name, field_last_name)

Step 2: Add a question right after the branch logic where field_full_name gets populated.

Step 3: Add JavaScript to that question:

  • Retrieve the full name from Embedded Data

  • Split it by space

  • Save the first word as first name

  • Save the remaining part as last name

This updates the Embedded Data fields so they can be used later in the survey or in reporting.

 

Survey Flow:


Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

// 1. Get the full name value from the embedded data field
var fullname = "${e://Field/field_full_name}";

// 2. Split the string by one or more spaces, and trim leading/trailing spaces
// The trim() ensures names like " John Doe " don't cause issues
// The /\s+/ regex handles multiple spaces between names
var nameParts = fullname.trim().split(/\s+/);

// 3. Initialize variables for first and last name
var firstName = "";
var lastName = "";

if (nameParts.length > 0) {
// Capture the first name (always the first element)
firstName = nameParts[0];

// If there is more than one word, the last word is considered the last name
if (nameParts.length > 1) {
lastName = nameParts[nameParts.length - 1];
}
}

// 4. (Optional) You can now store these back into Qualtrics Embedded Data fields
Qualtrics.SurveyEngine.setEmbeddedData("field_first_name", firstName);
Qualtrics.SurveyEngine.setEmbeddedData("field_last_name", lastName);

// For debugging, you can print the results to the console:
console.log("Full Name: " + fullname);
console.log("First Name: " + firstName);
console.log("Last Name: " + lastName);
});