- 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-20-2023 10:08 PM
Hello @-O-
Thank you for helping modifying the code. I made the changes exactly what you suggested and still I have no luck of getting it to work. When you get a chance, could you please try it in your PDI to see if it works. I might have screwed up somewhere. (See attached)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2023 04:56 AM
You're welcome.
I did test the solution before posting and it does work.
However you have just experienced what I was talking about: unless the description contains the exact correct name, the solution will fail.
This is really a very unreliable solution as it allows for every tiny little typing error to break it.
And that is what happens to you: you type Able instead of Abel - inverted letters e and l at the end.
If you correct the Description to contain a correct name, it will work.
Again, unless this is for the purpose of some exercise, the proper solution is to create a Catalog Item and have HR fill that in, not rely on e-mails.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 10:21 PM
Hi @-O-
Your provided code has been working really well. However, I'm currently running into another issue and hope you can provide assistance.
Your provided code works perfect if an email come in as follows:
From: Lopez,John C <jlopez@abc.com>
However, if an email contains like this, I need to grab email starting at "To"
From: Sharepoint Portal <no-reply@sharepointonline.com<mailto:no-reply@sharepointonline.com>>
Sent: Tuesday, January 24, 2023 8:20 AM
To: Lin,John<JohnLin@abc.com<mailto:JohnLin@abc.com>>
Subject: Test
I have tried to modify the code as follow, but that did not work.
var senderName = description.match(/^To:.+<([^<>]+)>$/mi);
Please help. Thank you again
- 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:35 PM
Hello @-O-
Your code works perfectly! You were a great helper. I learned a lot from you.
I'm going to sign up for beginning JavaScript class next month to get a better understanding how it works.
We sincerely thank you so much for all your help.