need to create RITM based from email or outlook like based on email content

Purushotham Ga2
Tera Contributor

HI experts,

email content:

-----------------

User  S Admin has been disabled due to inactivity.
* User Name - Testssrm_1
* Job Title - Security Service
*AD Last Logon - 11/08/2024 04:50:13
* Azure AD Last Sign-In - 11/08/2024 04:50:13
* Manager - Putt
* Manager Email ID - zyelynn.putt@abc.com
Business Process: Disablement: Testssrm_1 (Disabled)
Subject: Admin account Testssrm_1 disabled by AD automation due to inactivity
Details: Admin account Testssrm_1 disabled by AD automation due to inactivity and disabled on 2/11/2025 12:42:54 AM
--------------------
 
we have sr form 
--------------
name - Admin account disabled by AD automation due to inactivity1
variables like :-
-----------
Question                                                  type
----------                                                 --------------
User Name                                              single line text
Job Title                                                   single line text
AD Last Logon                                         date/time
Azure AD Last Sign-In                                   date/time
Manager Name                                                single line text(string)
Manager Email ID                                              single line text
------------------------------------------------------------------------------
 
need to create RITM based on email body and need to capture those info in RITM variables as well
 
please assist me asap.
 
10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Purushotham Ga2 

this link has solution using Flow, please enhance

Create RITM through inbound action by parsing mail body 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Purushotham Ga2 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Vishal Jaswal
Giga Sage

Hello @Purushotham Ga2 

There are two ways with which you can achieve your requirement:

1. Flow (No code or low code): https://www.youtube.com/watch?v=uLHCw2GA3lo&t=363s
ServiceNow official information and instructions: https://developer.servicenow.com/dev.do#!/learn/courses/xanadu/app_store_learnv2_flowdesigner_xanadu... 

2. Inbound Actions (System Policy > Email > Inbound Actions) - Development

Here is a sample Background script with the e-mail body example you shared: 

//var body = email.body_text; // In your inbound email Actions script you will use it to extract plain text body
var emailBody =
"User S Admin has been disabled due to inactivity.\n" +
"User Name - Testssrm_1\n" +
"Job Title - Security Service\n" +
"AD Last Logon - 11/08/2024 04:50:13\n" +
"Azure AD Last Sign-In - 11/08/2024 04:50:13\n" +
"Manager - Putt\n" +
"Manager Email ID - zyelynn.putt@abc.com\n" +
"Business Process: Disablement: Testssrm_1 (Disabled)\n" +
"Subject: Admin account Testssrm_1 disabled by AD automation due to inactivity\n" +
"Details: Admin account Testssrm_1 disabled by AD automation due to inactivity and disabled on 2/11/2025 12:42:54 AM";

// Initialize the Request Item (RITM) record
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.initialize();

// Item field (cat_item).. if you already have 'Admin account Testssrm_1 disabled by AD automation due to inactivity' as cat_item then use it's sys_id as it is a reference field
ritmGr.setValue('cat_item', 'YOUR_CATALOG_ITEM_SYS_ID');



// Extract values using regular expressions (https://regexr.com/)
var userNameMatch = emailBody.match(/User Name - (.+)/); // (.+) captures anything after the User Name - 
var jobTitleMatch = emailBody.match(/Job Title - (.+)/);
var adLogonMatch = emailBody.match(/AD Last Logon -\s*(.+)/);
var azureLogonMatch = emailBody.match(/Azure AD Last Sign-In -\s*(.+)/);
var managerMatch = emailBody.match(/Manager - (.+)/);
var managerEmailMatch = emailBody.match(/Manager Email ID - (.+)/);


// Set values in RITM variables. Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
ritmGr.variables.user_name = userNameMatch ? userNameMatch[1].trim() : '';
ritmGr.variables.job_title = jobTitleMatch ? jobTitleMatch[1].trim() : '';
ritmGr.variables.ad_last_logon = adLogonMatch ? new GlideDateTime(adLogonMatch[1].trim()) : '';
ritmGr.variables.azure_ad_last_sign_in = azureLogonMatch ? new GlideDateTime(azureLogonMatch[1].trim()) : '';
ritmGr.variables.manager_name = managerMatch ? managerMatch[1].trim() : '';
ritmGr.variables.manager_email_id = managerEmailMatch ? managerEmailMatch[1].trim() : '';


gs.info(userNameMatch ? userNameMatch[1].trim() : '');
gs.info(jobTitleMatch ? jobTitleMatch[1].trim() : '');
gs.info(adLogonMatch ? new GlideDateTime(adLogonMatch[1].trim()) : '');
gs.info(azureLogonMatch ? new GlideDateTime(azureLogonMatch[1].trim()) : '');
gs.info(managerMatch ? managerMatch[1].trim() : '');
gs.info(managerEmailMatch ? managerEmailMatch[1].trim() : '');

/* Insert RITM record in your actual inbound email action script.
var ritmSysId = ritmGr.insert();
if (ritmSysId) {
   gs.info("RITM created successfully with sys_id: " + ritmSysId);
} else {
   gs.error("Failed to create RITM.");
} */


Results:

vishal_jaswal_0-1742478980398.png


Please perform the development and let us know your results so that we all can learn together.


Hope that helps!

Purushotham Ga2
Tera Contributor

HI @Vishal Jaswal  -  i used the above script but it's not working like just populate the manager details only but it doesnt capture in variables. please assist me on this asap