- 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
02-14-2023 05:38 PM
You're most welcome.
As for working perfectly, as you will know more about JavaScript and RegExp, you will realize that regular expressions are more about "works most of the time" (in most cases), than it is about perfection. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 11:00 AM
Why don't you crate a Catalog Item HR shall use to request whatever is request, instead of writing an e-mail?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2023 10:15 PM
Thank you for your suggestion. HR is currently working with consultant to develop a few Catalog Item. That projects will takes sometime to starts. In the meantime, HR would like to continue to use email as a request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2023 04:58 AM
Maybe ask them to include the e-mail address instead of the name of the Requested for user then. It would also eliminate the problem of having multiple users with the same name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 07:23 AM
Good morning @-O-
If we going to have HR also include the e-mail address. How will it prevent the problem of having users with the same name. Do we need to modify the code? Thank you for your suggestion,