- 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-16-2017 01:40 AM
Also I believe you are trying to access Ticket#: I616584 from email subject, then the code should be
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-16-2017 02:19 AM
Hi,
I tried hard coding values as well but it is not working.
What is the "TEST"? if I understand correctly it is the incident number?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2017 02:24 AM
Anyhow just one question why I am not getting "help" commands when I am using CTRL+SPACE while writing script?
is it like that way only?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2017 02:40 AM
TEST is a way to search on logs for the number, You can search on logs Source=TEST. Did you get this log with any value?
Have you checked if your inbound action is triggered from mailbox received logs? Can you please share a screenshot of all tabs in your inbound action.
What I think is API is not setup to work as autocomplete in inbound actions.
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 03:04 AM