Need to extract Incident Number or Change Number from inbound email action

Nasir1
Tera Expert

Hi,

Not so good with the scripting aspect and would appreciate if someone can help.

I have a requirement that needs to extract the Change or Incident number from email subject.

The email comes from same email address, but the subject line is different.

For example the Subject Line can be Unplanned Change : CHG123456789

Or Update: Unplanned Outage: INC123456789

How can we run the script that look at the subject and grabs the incident or change number?

 

Thanks in Advance

1 ACCEPTED SOLUTION

Hi,

add similar regex for CHG also

var subject = email.subject.toString();

var regex = new SNC.Regex('/CHG\\d{9}/im');

var match = regex.match(subject);

gs.info(match);

If my response helped please mark it correct and close the thread so that it benefits future readers.

regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use RegEx to get

Sample script like this

var str = 'Update: Unplanned Outage: INC123456789';

var regex = new SNC.Regex('/INC\\d{9}/im');

var match = regex.match(str);

gs.info(match);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks How do I check the subject line in the same script if its change?
I am trying to avoid creating multiple inbound actions, since the email is coming from same email address only the subject line changes so I need a way to be able to extract either change or Incident number from subject

Hi,

add similar regex for CHG also

var subject = email.subject.toString();

var regex = new SNC.Regex('/CHG\\d{9}/im');

var match = regex.match(subject);

gs.info(match);

If my response helped please mark it correct and close the thread so that it benefits future readers.

regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar 

By using the above method, I could retrieve only one Incident number. Could you pls help here to retrieve more than one Incident from description field?