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

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @swapnil15 ,

You can do in this way

var text = email.body_text;

// Define regular expressions to match the patterns
var adLoginPattern = /AD Login - (\d+)/;
var emailPattern = /Email Address - (\S+)/;
var locationPattern = /Location - (\w+)/;
var areaPattern = /Area - (\w+)/;

// Function to extract values using regular expressions
function extractValue(text, pattern) {
    var match = text.match(pattern);
    return match ? match[1] : null; // Return the captured group (value) or null if not found
}

// Extract values using regular expressions
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();

 

You can replace to original values based on body text. 


Please mark as accepted solution & hit helpful !!! 

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..:)

Sure:

Dear Service Desk,

Our HR system has indicated that Simon Beggs is due to leave the company on 16-02-2024.

Thanks,
IT Services

Hi @swapnil15 , 

 

Refer to my above solution given. 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..:)

Hi @Sohithanjan G ,
I have used below script as given by you:

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

    // Implement email action here
    var text = email.body_text;

    // Define regular expressions to match the patterns
    var adLoginPattern = /AD Login - (\d+)/;
    var emailPattern = /Email Address - (\S+)/;
    var locationPattern = /Location - (\w+)/;
    var areaPattern = /Area - (\w+)/;

    // Function to extract values using regular expressions
    function extractValue(text, pattern) {
        var match = text.match(pattern);
        return match ? match[1] : null; // Return the captured group (value) or null if not found
    }

    // Extract values using regular expressions
    var adLogin = extractValue(text, adLoginPattern);
    var email = extractValue(text, emailPattern);
    var location = extractValue(text, locationPattern);
    var area = extractValue(text, areaPattern);

    current.u_adlogin = adLogin;
    current.u_mailid = email;
    current.u_leaver_location = location;
    current.u_area = area;
    current.insert();



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

 

And below is what I am getting in the RITM fields:

swapnil15_0-1708923945350.png



The Ad Login is empty, Mail has an asterisk(*) before it, leavers location and area are parsed half.

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..:)