- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 09:21 AM
Hello,
We are receiving service request submitted from using emails. The RITM description field captures the entire email.
I would like to search the name "From: John,Lopez" in the RITM description field and populate in "Requested For" field.
See attached
Could someone please help? Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 06:31 PM
You are using an after business rule to update current. That beaks rule no. 1 of Business rules: whenever the current record is to be updated, it must be done using a before business rule.
Rule no. 2 being: whenever a different record than the current one needs to be updated, it must be done using an after business rule.
The other issue is the RegExp itself; it should be:
/^From:\s*(.+)$/mi
Another issue is that you are using the name directly to set the field. You need to fetch the user's sys_id and use that to set the value of the field:
GetIDValue('sys_user', )
Something like:
// Script to extract sender name from RITM description and set as requested for
// Get RITM description
var description = '' + current.description;
// Use regular expression to extract name from "From" field
var senderName = description.match(/^From:\s*(.+)$/mi);
// Set extracted name as requested for
current.requested_for = GetIDValue('sys_user', senderName[1]);
Of course the code should check that the value returned by GetIDValue is not null and only set the requested for if it is not. This is also a very fragile solution as the slightest mistype, even an additional or missing space in the name and it will not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 10:50 PM
Hello,
Something simple like
var senderName = description.match(/^To:.+<mailto:([^<>]+)/mi);
should do it, but if you want a solution where you match either the original patter or this one, a different RegExp is needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 01:52 PM
Thank you for helping @Basheer
Here is what I did, but I have no luck of getting it to work. I must did something incorrect.
1. For testing purposes, I created a Business Rule with Before on update (See attached)
2. Opened the existing RITM and modified the description with "From:Able Tuter" (See attached)
3. Save the record, but it did not update the Requestor For field (See attached)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 06:28 PM - edited 01-20-2023 09:19 AM
Hi @Radhika11 ,
Slight mistake in code, it should be includes not include(my typo in previous reply);
2 things:
Test on insert as well as update in business rule instead of just update
keep the condition as requested for is not empty as a best practice
We will debug the things,
Do script as below and let me know what messages have been printed.
var description = current.description;
gs.addInfoMessage("This is description : " + description);
if(description.includes("From:")){
gs.addInforMessage("Entered if");
var firstLine = description.split('\n')[0];
gs.addInfoMessage("First Line : "+firstLine);
var split= firstLine.split(":");
var userName = split[1];
gs.addInfoMessage("userName : "+userName);
var userRecord = new GlideRecord("sys_user");
userRecord.addQuery("name",userName);
userRecord.query();
if(userRecord.next()){
current.requested_for = userRecord.getUniqueValue();
}
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 09:10 AM
Good morning @Basheer
The code still did not working. (See attached Logs). Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 09:19 AM
Hi @Radhika11 ,
There seems typo in my previous reply. can you correct this line and show me the logs
var userName = spllit[1]; //this is worng spelt
var userName = split[1]; //Replace to this
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 06:09 PM
Hello @Basheer
I followed your suggestion and replaced the split line, but still I could not get it to work. Please take a look at attached short video.