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

It is same what I said before, the condition is wrong. Please correct the extra space in front of " Incident Number"



find_real_file.png



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


step1.PNG


after correction


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


step1.PNG


Hi,



Finally its working...thank you so much for your help..it was greatt


Great! Happy to help



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response