- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2017 09:14 AM
Hi,
I need to write a script to extract a number from the subject of the mail.user sends a mail to dev****.servicenow.com.
From System Policy > Email > Inbound Actions I have configured:
and in actions tab I have mentioned the actions when a mail is received:
Now I need to write a script that may take a number from the mail subject and insert it in a custom field.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2017 03:40 AM
The code you added in the previous screenshot is wrong.
Can you please replace it with this
var rsubject=email.subject;
var keyword="Ticket#: ";
var len = keyword.length;
var key = rsubject.indexOf(keyword); //Assuming this text would never change
if(key > 0){
var number = rsubject.substring(key+len, 7);
gs.log(number, "TEST"); //Try logging number
current.u_ast_id = number;
current.update();
}
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2017 09:17 AM
Hi,
email.subject in the Inbound Action script returns you the email subject. You can perform additional validation on it as per your logic.
var key = email.subject.indexOf("search_keyword");
if(key > 0){
current.field_name = // extract content from email.subject using substring, key as index or other java script functions
}
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2017 01:22 AM
Hi ,
Thank you for the hint.
I applied this script:
var rsubject=email.subject;
var key = rsubject.indexOf("I");
if(key > 0)
{
current.u_ast_id = rsubject.substring(key,6);// extract content from email.subject using substring, key as index or other java script functions
current.insert();
}
But the script is not updating the "u_ast_id" field or rather not inserting any value in this field.
[Though the email received is shown in the incident for which the mail is being sent]
but no ID is being inserted
The ID field is empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2017 01:30 AM
Hi,
Should it be current.update(); ?
Was the incident already created and What is Type of Target field?
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2017 01:35 AM
Hi,
I will try current.update..Yes the incident was already created.
Based on a mail I am supposed to insert the "ID" for that incident.
Type of field is "string"