- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 08:16 AM - edited 02-23-2024 08:19 AM
Hi All,
SNOW receives a mail as below:
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 01:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 08:51 AM - edited 02-23-2024 09:02 AM
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 !!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 09:07 AM
Sure:
Dear Service Desk, Our HR system has indicated that Simon Beggs is due to leave the company on 16-02-2024.
Thanks, |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2024 10:50 AM
Hi @swapnil15 ,
Refer to my above solution given. Request you to mark as Accepted Solution & Hit helpful button.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 09:07 PM
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:
The Ad Login is empty, Mail has an asterisk(*) before it, leavers location and area are parsed half.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 01:08 AM
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.