How to remove duplicate tickets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2022 01:04 AM
Hi,
My requirement is If 2 incidents tickets are submitted within 10 minutes with the came caller and same short description then mark the 2nd created as duplicate, then change the summary to "duplicate" and close/cancel the change.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2022 03:01 AM
Hello Akhil,
Create an after insert Business rule that will query the incident table to check if there are already incidents for that caller with that same short description and created in the last 10 minutes. If so, set the resolution code to "duplicate and set the incident to resolved.
You can achieve if with a code similar to this:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("incident");
gr.addEncodedQuery("sys_created_onRELATIVEGT@minute@ago@10^short_description=" + current.short_description + " ^caller_id=" + current.caller_id);
gr.query();
if(gr.next()){
current.close_code = "Duplicate";
current.close_notes = "Duplicate";
current.state = 6; //Resolved
current.update();
}
})(current, previous);
Hope this helps!!
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2022 06:13 AM
Hi Filipe,
Thank you for your response.
When I'm using this code and creating an incident ticket, after saving the ticket, the state is automatically changed to resolved state. But my requirement is when the caller and short description is same then only the state is changed to resolved.
Regards,
Akhil

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2022 01:52 PM
Hi Akhil,
Since this is an after insert business rule, that query was already picking the current record!! My bad! 🙂
Please use the following code (that will exclude the current record from the query):
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("incident");
gr.addEncodedQuery("sys_created_onRELATIVEGT@minute@ago@10^short_description=" + current.short_description + " ^caller_id=" + current.caller_id + "^sys_id!=" + current.sys_id);
gr.query();
if(gr.next()){
current.close_code = "Duplicate";
current.close_notes = "Duplicate";
current.state = 6; //Resolved
current.update();
}
})(current, previous);
You can try it out now!
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz