how to link emails to incidents using the INC reference

Dubz
Mega Sage

Hi,

Just wondering if anyone can advise me on the script i would require to have new emails update a current incident if they have the INC reference in the subject line? We have various customers who communicate with us using their own ticketing systems so Service Now classifies their emails as new. We can get them to add the INC reference to the subject line but SN will only use that to update a current incident if the email is classified as a reply.

1 ACCEPTED SOLUTION

David,



Can you share the subject line you used?


Ideally if it contains INCxxxxxxx it should process the script since the condition meets.



Also change the script to following, this should update your short description to the email body text and ends processing of inbound mail against other email actions.



gs.include('validators');


if (current.getTableName() == "incident")


{


  var index = email.subject.indexOf("INC");


  var incNumber = email.subject.substring(index,index+10);


  gs.log(incNumber,'test');



  var gr = new GlideRecord('incident');


  gr.addQuery('number',incNumber);


  gr.query();



  while(gr.next())


  {


gr.short_description = email.body_text;


  gr.update();


event.state="stop_processing";


  }


}


View solution in original post

11 REPLIES 11

Hi David,


Can you please update your requirement more in detail so i could help you the tweaked script?


HI Harneet,



I have zero knowledge of scripting so i'm not going to be much help in identifying where this is failing!



All i need is for new emails to update incidents rather than create new ones if there is an INC reference in the subject line.



I tried changing the order on the inbound action i created with your script to ensure it was processed before Create Incident but to no avail, it's still skipping this rule.


David,



Can you share the subject line you used?


Ideally if it contains INCxxxxxxx it should process the script since the condition meets.



Also change the script to following, this should update your short description to the email body text and ends processing of inbound mail against other email actions.



gs.include('validators');


if (current.getTableName() == "incident")


{


  var index = email.subject.indexOf("INC");


  var incNumber = email.subject.substring(index,index+10);


  gs.log(incNumber,'test');



  var gr = new GlideRecord('incident');


  gr.addQuery('number',incNumber);


  gr.query();



  while(gr.next())


  {


gr.short_description = email.body_text;


  gr.update();


event.state="stop_processing";


  }


}


Late repsonse on this but thanks for the solution Harneet. I had to remove the if (current.getTableName() == "incident") line as, at the time it was processing the email, it didn't know it was an incident so it was skipping the rule but it works perfectly now.


Hi,

Thanks for the above script.

If I want to update the existing incident by using the 3rd party reference number on the subject line, for example #monitoring 12345.

If the monitoring number does not match then inbound email should create a new incident.

How can I do this? I have tried couple of scripts from the community but nothing worked. Many thanks in advance.