- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 01:41 PM - edited 02-26-2024 01:45 PM
Hi All,
I have an ask to create a RITM whenever an email is received in ServiceNow and the data needs to be parsed, and pushed to the variables in the catalog that creates the RITM.
Below is how the mail body is received in SNOW:
Dear Service Desk,
Our HR system has indicated that Simon Beggs is due to leave the company on 16-02-2024.
AD Login - op-simonb1
Email Address - Simon.Beggs@norbrook.co.uk
Location - Norbrook Laboratories Ltd
Area - Armagh Road
Thanks,
IT Services
Till now, I have used regex to parse the data into the fields on RITM. The inbound script looks as below:
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
var text = email.body_text;
gs.log('text is: ' + text);
// Define regular expressions to match the patterns
var adLoginPattern = /AD Login - (.+)/;
var emailPattern = /Email Address - (.+)/;
var locationPattern = /Location - (.+)/;
var areaPattern = /Area - (.+)/;
var namePattern = /indicated that (.+) is due/;
var DepartDatePattern = /([A-Za-z0-9]+(-[A-Za-z0-9]+)+)/i;
// Function to extract values using regular expressions
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
}
}
// 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);
var name = extractValue(text, namePattern);
var depdate = extractValue(text, DepartDatePattern);
gs.log('ad login :' + adLogin);
gs.log('email is: ' + email);
gs.log('location is: ' + location);
gs.log('area is :' + area);
gs.log('name is :' + name);
gs.log('depart date: ' + depdate);
current.u_adlogin = adLogin;
current.u_mailid = email;
current.u_leaver_location = location;
current.u_area = area;
current.u_ad_login = name;
current.u_departure_date = depdate;
// current.u_departure_date.setDisplayValue(depdate);
current.insert();
// Now set catalog variables with parsed values
var ritmVariables = current.variables;
if (ritmVariables) {
ritmVariables.staff_member_name = name;
ritmVariables.date_of_departure = depdate;
ritmVariables.email_address = email;
ritmVariables.ad_login = adLogin;
ritmVariables.location = location;
ritmVariables.area = area;
ritmVariables.update();
}
})(current, event, email, logger, classifier);
- I am able to parse the data from mail body and push it in the fields as below in the newly created RITM.
Ask is - instead of the above fields (ad login, location, mail, area, departure date), the parsed data from mail needs to be pushed into the variables of a catalog item and then create an RITM from that catalog automatically. Or create an RITM and push the data into the variable, either way.
Below is the catalog item with variables:
So basically - I need an automated flow where, whenever an email is received in SNOW, the mail body needs to be parsed and pushed to the catalog item as above and create an RITM automatically.
I got the parse data in the fields but not sure how to push that data into the variables on RITM. The catalog has a cart section in the RITM where the data needs to be visible, something like below:
Or any other path to complete the ask other than one I mentioned above is appreciated! I came across few threads on forum as this one.
But it didn't helped. The RITM was not created when I use the script from the mentioned thread.
I am also not aware of CART API and CARTJS on how to use it.
Can anyone help on how to achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 04:37 AM
@swapnil15 : This can be achieved by using flow designer.
1. Set trigger as inbound email and set condition as required.
2. There is ServiceNow flow action provided by ServiceNow on share "Parse Email body text" Attached word document for steps to download it for reference.
3. In flow , there is provision to create flow variables -click on three dots at right upper corner- flow variables option- Using this option you can create variables to store values from email body text after parsing. (though script or dot walking should be available). For every value create flow variable which will store respective variable required on this request.
4. then use "Submit catalog item request" step- pass your catalog item and in variables pass the above each flow variables by dot walking. This will create request automatically.
Give a try. Hope it helps. Kindly mark helpful/accepted if it helps.
Regards,
Priyanka Salunke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 05:58 AM
I tried with and without the conditions, both didn't worked.
Not sure, what I am missing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 04:37 AM
@swapnil15 : This can be achieved by using flow designer.
1. Set trigger as inbound email and set condition as required.
2. There is ServiceNow flow action provided by ServiceNow on share "Parse Email body text" Attached word document for steps to download it for reference.
3. In flow , there is provision to create flow variables -click on three dots at right upper corner- flow variables option- Using this option you can create variables to store values from email body text after parsing. (though script or dot walking should be available). For every value create flow variable which will store respective variable required on this request.
4. then use "Submit catalog item request" step- pass your catalog item and in variables pass the above each flow variables by dot walking. This will create request automatically.
Give a try. Hope it helps. Kindly mark helpful/accepted if it helps.
Regards,
Priyanka Salunke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 01:35 PM
Is the share "Parse Email body text" compatible with Utah/Vancouver? Looking to attempt to use this on both versions to ensure functionality, but thought to ask ahead of time.
Thank you!
Joel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 01:06 AM - edited 03-01-2024 01:13 AM
Hi @Joel O :- Yes, I have tested on my PDI (Vancouver version). It is working fine. For more details, please refer this attached document. It is recommended to test in your pre-prod instance then apply in production.
Check out this video for demo of using this action.
https://www.youtube.com/watch?v=uLHCw2GA3lo
Hope it helps. Kindly mark helpful/accepted if it helps.
Regards,
Priyanka Salunke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 07:47 AM - edited 03-01-2024 07:47 AM
Thank you @Priyanka_786
Just tested and it works as expected for String fields. 👍
Reading the documentation, I'm not understanding when he was referring to populating a Reference field. I have a catalog item that does have Reference fields that I would like to populate from parsing the text in the email. Would you be able to explain further what he was referring too? Also the images on the doc surrounding this step is not clear for me to see as I'm confused at what point in my Flow would I add a lookup operation.
Your help would be greatly appreciated.