Script to extract a number from the mail subject line

nehasr1288
Tera Expert

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:

Capture.png

and in actions tab I have mentioned the actions when a mail is received:

Capture.png

Now I need to write a script that may take a number from the mail subject and insert it in a custom field.

1 ACCEPTED SOLUTION

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


View solution in original post

20 REPLIES 20

Dave Smith1
ServiceNow Employee
ServiceNow Employee

Perhaps a regular expression could be what you're after - it can strip out leading/succeeding characters to leave data of interest.