Remove Characters from a String / Embedded Data Field | XM Community
Skip to main content

Hello, I have been attempting to remove the 13 characters on the left of an EmbeddedData field. I have found some resources and a somewhat similar example, but have not been having luck. 

 

For this survey we wanted two links per potential respondent, with different features for our call team and the email/web version, so we upload them twice. Once with their email as written and once with PHONE.VERSION. in front of it. The issue is we want to pipe in their email address at the end so our call staff sees that and can confirm, without PHONE.VERSION in front of it. 

What I am seeking to do is have ${e://Field/RecipientEmail} display as their email without “PHONE.VERSION” -- essentially removing the first 13 characters, if the embedded data field PhoneFlag=1. Here is the javascript I have been trying:

Qualtrics.SurveyEngine.addOnload(function() {
    // Get the value of PhoneFlag
    var phoneFlagValue = "${e://Field/PhoneFlag}";

 

    // Check if PhoneFlag equals 1
    if (phoneFlagValue === "1") {
        // Get the email address of the respondent
        var originalEmail = "${e://Field/RecipientEmail}";

 

        // Remove the first 13 characters using substring
        var modifiedEmail = originalEmail.substring(13);

 

        // Set the modified email to an embedded data field
        Qualtrics.SurveyEngine.setEmbeddedData('ModifiedEmail', modifiedEmail);
    }
});

 

I then try to insert ${e://Field/RecipientEmail} and ${e://Field/ModifiedEmail} in the question. ${e://Field/ModifiedEmail} returns blank and ${e://Field/RecipientEmail} gives the email that we had in the upload file. 

 

I apologize for my lack of knowledge but appreciate any help the forum grants me. Happy to correspond with additional details. 

Still not working but updated it:

 

Qualtrics.SurveyEngine.addOnload(function() {
        var originalEmail = "${e://Field/RecipientEmail}";
        let strippedEmail;
        let stripString = "PHONEVERSION."
        
        if (originalEmail.startsWith(stripString)) {
            strippedEmail = originalEmail.substring(stripString.length);
        } else {
            strippedEmail = originalEmail
        }

        // Set the modified email to an embedded data field
        Qualtrics.SurveyEngine.setEmbeddedData('ModifiedEmail', strippedEmail);
});

 

Calling this but comes up blank:

${e://Field/ModifiedEmail}


Colleague assisted and it works. We found another article that was of assistance.

 

setEmbeddedData has it seems been deprecated. | XM Community (qualtrics.com)

 

Fixes were to put the java script earlier in the survey, not on question it was used on and to update code with “JS” in last line. Also adding __js_ModifiedEmail to embedded data in survey flow

 

Qualtrics.SurveyEngine.addOnload(function() {
        var originalEmail = "${e://Field/RecipientEmail}";
        let strippedEmail;
        let stripString = "PHONEVERSION."
        
        if (originalEmail.startsWith(stripString)) {
            strippedEmail = originalEmail.substring(stripString.length);
        } else {
            strippedEmail = originalEmail
        }

        // Set the modified email to an embedded data field
        Qualtrics.SurveyEngine.setJSEmbeddedData('ModifiedEmail', strippedEmail);
});

 

And use ${e://Field/__js_ModifiedEmail} in the question text.


Leave a Reply