How to update existing incident ticket using inbound email action

String
Kilo Sage

Hi Team ,

Am using below code to update the existing incident records using inbound email action ,instead of updating ,service now creating  a new incident .below is my code 

 

 var caseGR = new GlideRecord(‘incident’);

 var Number = emailBody.incident_ticket;

caseGR.addQuery('number', Number);

caseGR.query();

if (caseGR.next()) {

 current.state = 10;

current.description='Reopen ticket';

   current.update();

}

am trying to use  current.update(); instead of caseGR.update(); because I want to capture email in activity log (incident )

 

Please guide me with best practices 

5 REPLIES 5

Tony Chatfield1
Kilo Patron

Hi, the platform should be identifying your existing incident via the email 'type' IE reply
and watermark or subject line, then setting the related task as the 'target' record for your sys_email record?

Inbound email action processing (servicenow.com)

 

If this is not occurring and you cannot resolve the issue by altering the emails being sent to the instance?
Then, you would need to lookup the incident in an inbound action using GlideRecord script, then 'update' any matched record, very much like your script but not using 'current' as this would result in a new record.

Untested but try this

var caseGR = new GlideRecord(‘incident’);
var Number = emailBody.incident_ticket;
caseGR.addQuery('number', Number);
caseGR.query();
if (caseGR.next()) {
 caseGR.state = 10;
 caseGR.description='Reopen ticket';
 caseGR.update();
}
//If required to insert a new record where a match is not found
else {
//map your fields for a new task record

current.insert();
}

If a task is still being created, it may be from a different inbound action running after this one?

In this case you can add this at bottom of your script.

event.state = "stop_processing";

 



Hi @Tony Chatfield1 Thanks for your quick reply 

While we using above code (caseGR.update) ,existing ticket is getting updated but email info is not updated in  incident activity logs and we observed in email logs target is empty 

String_0-1705316615222.png

is there any way to update the activity logs and email logs target  ?

Sandeep Rajput
Tera Patron
Tera Patron

@String Did you check if any other inbound email action is defined on the incident table? Also put appropriate logs inside your inbound email action script to check if this inbound action is finding a match for the existing record.

Hi @Sandeep Rajput  thanks for your quick reply ,

If am using the below code 

if (caseGR.next()) {

 caseGR.state = 10;

 caseGR.description='Reopen ticket';

 caseGR.update();

}

Ticket is getting updated but email info is not captured in incident ticket activity logs and we observed in email logs target is empty

String_0-1705317625970.png

is there any way to update the activity logs and email logs target