Inbound Actions - need to find INC number and 3rd party ref

Carl Fransen1
Tera Guru

Hi Team,

I have a requirement to update an Incident from an email - and not log a new one.   I need to grab the INC number from the subject to perform an update to that INC ticket - plus grab the 3rd party ref number and add it to the incident field.

The subject is always in this format, the bold text is what changes between the types of updates coming back from the 3rd party ticket software:  

                                      Ticket Received - IT Service Desk - Incident INC0010036 has been resolved. - Ticket Ref. #4392

Therefore I need to find the INC to ensure I know that this is an update (new inbound action as not a reply) - and add the email to the work notes/comments of the existing INC.

Additionally i need to grab the '4382' and add this to the '3rd_party_ref_number' field i created on the incident record.

I have tried a bunch of code (copied from the community) - but all these only create new records, none of them update the tickets:

CODE1:

 

var numberPattern = "/INC\[0-9]{7}/"; //Looking for INC plus 0-9 numbers, seven numbers in total    

var reg = new SNC.Regex(numberPattern);    

var matchedNumber = reg.match(email.subject);    

 

if (JSUtil.notNil(matchedNumber)) { //matchedNumber will be NULL if a match is not found in the email subject.   If NULL we know this is a new email    

      var incidentRec = new GlideRecord("incident");    

      incidentRec.addQuery("number", matchedNumber); //Update this with your old ticket number field column name    

      incidentRec.query();    

      if (incidentRec.next()) {    

              incidentRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;    

              incidentRec.update();    

 

  }  

      current.insert();    

}    

CODE2:

var incnr = new GlideRecord("incident");

var lowmail = email.subject.toLowerCase();

incnr.addQuery('number', lowmail.substr(lowmail.indexOf('inc')+0,10));

incnr.query();

if(incnr.next()){

//event.state="stop_processing";

} else {

current.short_description = email.subject;

current.description = email.body_text;

current.contact_type = "email";

current.insert();

}

CODE3:

var tckstr = email.subject.toString();  

  var tckpos=tckstr.indexOf("INC");  

  var tcknum= email.subject.substr(tckpos,10);  

  incTicket=new GlideRecord('incident');  

  incTicket.addQuery('number', tcknum);  

  incTicket.query();  

  while (incTicket.next()) {  

  flagticket=true;  

  updateTicket(incTicket);  

incTicket.update();  

}  

Can anyone help with this - needed for a client implementation due this week!

Thanks

Carl.

1 ACCEPTED SOLUTION

Harneet Sital
Mega Sage
Mega Sage

Hi Carl,



how to link emails to incidents using the INC reference


I tried the following scenario and works and yours looks the same so you can try changing the script accordingly.



In the condition builder you can write Subject contains INC or in the script match the three letters followed by 7 digits.



gs.include('validators');


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


{


  //This gets you the INC number similar code can be used to get the ref number in your case.


  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.u_description = email.body_text;


  gr.update();


  }


}


View solution in original post

5 REPLIES 5

@Carl Fransen @Harneet Sital I have used your both script in inbound action, its created new record as well as updating given record. Please give the best solution