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

Sumanth16
Kilo Patron

Hi @swapnil15 ,

 

Please refer to below thread:

https://www.servicenow.com/community/developer-forum/retrieving-email-body-variables-for-population-...

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

I am sorry, how will that help with the requirement?

Minh Huy Lam Qu
Giga Sage

Hello @swapnil15 ,

 

You can use the CartJS API ServiceNow Developers to create it.

In the inbound action you can check the string value of the email body, then get the necessary value and use the CartJS API.

 

Regards,

Huy Lam

Hi Minh,

Isnt that cartjs api is used to push the data to variables directly? Can you elaborate on how I can use this?