How to update existing incident ticket using inbound email action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2024 02:42 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2024 06:38 PM
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";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 03:05 AM
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
is there any way to update the activity logs and email logs target ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2024 08:22 PM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 03:20 AM
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
is there any way to update the activity logs and email logs target