
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 04:51 PM
G'day all,
I've a requirement such that as soon as an email will be received an Inbound Email Action Script should run, which will fetch the incident number from the body of that email and put it into a custom field created on Incident table.
The email received is like this:
The incident number highlighted in Yellow should be trimmed from the email body and should be placed in a custom field - u_new_incident field on Incident Table.
Can some do me a massive favor by providing script that can be used to achieve this requirement.
Cheers-
Rahul J.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2019 08:55 PM
Finally, I found a solution to this requirement.
I created an Inbound Email Action like this:
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
var rSubject=email.subject;
var bod=email.body_text;
var bod1=bod.toString();
var rBody=bod1.substring(0,12);
var inc1= new GlideRecord('incident');
inc1.addQuery('number',rSubject);
inc1.query();
gs.print("rows"+ inc1.getRowCount());
if (inc1.next()){
inc1.u_new_incident=rBody;
inc1.update();
}
})(current, event, email, logger, classifier);
And, everything worked smoothly. A big shoutout to community members who helped me in achieving this.
Cheers-
Rahul J.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 05:07 PM
It would be better if you could get the email which is being sent to ServiceNow, had a column header associated with it. E.g.:
If the email body has the following content:
Incident Number: RXINC0013100
You could access it in your inbound action using:
email.body.incident_number;
The following documentation explains how to use variables from email body in your inbound action:
Your inbound action code could look like this if you had an incident number column in the body:
current.u_new_incident = email.body.incident_number;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 05:20 PM
Cheers I'll give it a shot and then I'll get back to ya.
Thanks for ya response.
Cheers-
Rahul J.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 05:35 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2019 06:38 PM
I didn't suggest to have the incident number in the Subject, I suggested it to be in the body / message with a column header, like:
Email Body
-----------
Incident Number: INC1234567
You could get the email body changed and try the previous code.
But if you prefer having the incident number in the subject, then you can use:
current.u_new_incident = email.subject;
Hope this helps!
Cheers,
Manish