Parsing Inbound Email after Yokohama

athavichith
Kilo Sage

Is anyone experiencing issues of parsing of name/value pairs for Inbound Email after Yokohama. I am noticing that my incident fields are populating to the name/value pair I had set in my script. 

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@athavichith 

share your script which was working earlier.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Community Alums
Not applicable

Hi @athavichith ,

Yes, after the Yokohama upgrade, several users have reported issues with how name/value pairs are parsed from inbound emails. In earlier versions of ServiceNow, if you included name/value pairs in the email body (like short_description=Network issue), the system would interpret them more leniently and populate the corresponding fields. However, in Yokohama, the inbound email processing logic has been updated and now handles parsing more strictly. This means that if the format isn’t exactly right, or if the field isn’t writable or recognized, the values might be ignored or incorrectly applied. As a result, some fields on the incident or other records might be populated with the literal name/value strings instead of properly parsed values.

To work around this, it’s recommended to directly set field values in your inbound email script using target.fieldname = value rather than relying on body parsing. If you still want to use name/value parsing, ensure each pair is correctly formatted on a new line and matches valid field names. You can also disable automatic parsing using email.parseBody = false and manually extract the values from the body. Reviewing the sys_email logs can also help identify how the email was processed and why fields were not updated as expected.

Thank you Tejas!

Here is my script:

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

    // Function to convert a string to title case
    function toTitleCase(str) {
        return str.toLowerCase().replace(/\b\w/g, function(char) {
            return char.toUpperCase();
        });
    }

    // Extract the phone number from the email body
    var phoneNumber = email.body.phone;

    // Remove leading "1" from phone number if present
    if (phoneNumber && phoneNumber.startsWith("1")) {
        phoneNumber = phoneNumber.substring(1).trim();
    }

    // Convert category and subcategory to title case
    var category = toTitleCase(email.body.category || '');
    var subcategory = toTitleCase(email.body.incident_subcategory || '');

    //set location
    var locationName = toTitleCase(email.body.location || '');
    var locationSysId = getLocation(locationName);
    if (locationSysId) {
        current.location = locationSysId;
    }


    // Map fields to the current record
    current.caller_id = email.body.name;
    current.u_best_contact_phone_num = phoneNumber;
    current.category = category;
    current.subcategory = subcategory;
    current.location = getLocation(email.body.location);
    current.work_notes = email.body.brief_description;

    // Assignment groups
    var afterHoursGroup = '0f32deb09773995030aab2a3f153af35';
    var serviceDeskGroup = '4b329e3c97fb9550cc467d021153afd1';

    // Instantiate GlideSchedule with your cmn_schedule sys_id
    var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //6:30AM to 5:00PM weekdays excluding holidays schedule
    var now = new GlideDateTime();

    // Check if current time is within business hours
    var isBusinessHours = schedule.isInSchedule(now);

    if (isBusinessHours) {
        current.assignment_group = serviceDeskGroup;
    } else {
        current.assignment_group = afterHoursGroup;
    }


    function getLocation(location) {
        var locgr = new GlideRecord('cmn_location');
        locgr.addEncodedQuery('u_display_nameSTARTSWITH' + location); // or use 'name' depending on your instance setup
        locgr.query();
        if (locgr.next()) {
            return locgr.sys_id.toString();
        }
        return null;
    }


})(current, event, email, logger, classifier);

Here is sample inbound email:

Dear IT Service Desk:We received the following case and need to route to you for additional assistance. Here is some information that will help you assist the customer in resolving their issue:Caller Information:
Name: John Doe
Phone: 1 555-555-5555
Email: Edward.Anderson@test.com
Location: Headquarters


theITSupportCenter Information:
ITSC Ticket Number: 01427108
Case Date: 4/28/2025
Category: Application
Incident Subcategory: ServiceNow


Description:
AdvisorCommentJeff HolmesA: Test case no serviceJeff HolmesSending test case notificationJeff Holmestest commentJeff Holmestest test test
Thank you for assisting the Customer
C1TM3CKNC23SBLEIBL
 
 
 
 


@athavichith 

try this

(function runAction(current, event, email, logger, classifier) {
    // Function to convert a string to title case
    function toTitleCase(str) {
        return str.toLowerCase().replace(/\b\w/g, function(char) {
            return char.toUpperCase();
        });
    }

    // Extract the phone number from the email body
    var phoneNumber = email.body.match(/Phone:\s*(\d+)/i);
    if (phoneNumber) {
        phoneNumber = phoneNumber[1];
        // Remove leading "1" from phone number if present
        if (phoneNumber.startsWith("1")) {
            phoneNumber = phoneNumber.substring(1).trim();
        }
    }

    // Extract other fields from the email body
    var name = email.body.match(/Name:\s*(.*)/i);
    var location = email.body.match(/Location:\s*(.*)/i);
    var category = email.body.match(/Category:\s*(.*)/i);
    var subcategory = email.body.match(/Incident Subcategory:\s*(.*)/i);
    var briefDescription = email.body.match(/Description:\s*(.*)/i);

    // Convert category and subcategory to title case
    category = category ? toTitleCase(category[1]) : '';
    subcategory = subcategory ? toTitleCase(subcategory[1]) : '';

    // Set location
    var locationName = location ? toTitleCase(location[1]) : '';
    var locationSysId = getLocation(locationName);
    if (locationSysId) {
        current.location = locationSysId;
    }

    // Map fields to the current record
    current.caller_id = name ? name[1] : '';
    current.u_best_contact_phone_num = phoneNumber;
    current.category = category;
    current.subcategory = subcategory;
    current.work_notes = briefDescription ? briefDescription[1] : '';

    // Assignment groups
    var afterHoursGroup = '0f32deb09773995030aab2a3f153af35';
    var serviceDeskGroup = '4b329e3c97fb9550cc467d021153afd1';

    // Instantiate GlideSchedule with your cmn_schedule sys_id
    var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); // 6:30AM to 5:00PM weekdays excluding holidays schedule
    var now = new GlideDateTime();

    // Check if current time is within business hours
    var isBusinessHours = schedule.isInSchedule(now);

    if (isBusinessHours) {
        current.assignment_group = serviceDeskGroup;
    } else {
        current.assignment_group = afterHoursGroup;
    }

    function getLocation(location) {
        var locgr = new GlideRecord('cmn_location');
        locgr.addEncodedQuery('u_display_nameSTARTSWITH' + location); // or use 'name' depending on your instance setup
        locgr.query();
        if (locgr.next()) {
            return locgr.sys_id.toString();
        }
        return null;
    }
})(current, event, email, logger, classifier);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader