We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Parse inbound mail body data to RITM

swapnil15
Tera Contributor

Hi All,

SNOW receives a mail as below:

swapnil15_0-1708704829883.png

 

I have 4 fields created on RITM table u_name, u_mailID, u_location and u_area. I want to create a RITM once the above mail is received and push the value from mail to the above fields mentioned on RITM. I have created an inbound action, need help on how to put the values from body to fields.

1 ACCEPTED SOLUTION

Hi @swapnil15 ,

Try with this updated code:

var text = email.body_text;

var adLoginPattern = /AD Login - (.+)/;
var emailPattern = /Email Address - (.+)/;
var locationPattern = /Location - (.+)/;
var areaPattern = /Area - (.+)/;

function extractValue(text, pattern) {
    var match = text.match(pattern);
    return match ? match[1].trim() : null; // Return the captured group (value) or null if not found
}

var adLogin = extractValue(text, adLoginPattern);
var email = extractValue(text, emailPattern);
var location = extractValue(text, locationPattern);
var area = extractValue(text, areaPattern);

current.u_name = adLogin;
current.u_mailID = email;
current.u_location = location;
current.u_area = area;
current.insert();

 

Request you to mark as Accepted Solution & Hit helpful button. 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

View solution in original post

11 REPLIES 11

Thanks a lot.

I handled the * as below:

 function extractValue(text, pattern) {
        var match = text.match(pattern);
        gs.log('match is: ' + match);
        if (match) {
            // Remove asterisks from the captured group (value) if found
            var value = match[1].replace(/^\*|\*$/g, ''); // This regex removes asterisks from start and end of the string
            return value.trim(); // Trim any extra whitespace
        } else {
            return null; // Return null if not found
        }
    }

Sohithanjan G
Kilo Sage

Hi @swapnil15 , 

Request you to mark as Accepted Solution & Hit helpful button. 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)