diff --git a/Server-Side Components/Business Rules/Prevent Duplicate Incident Creation within 24 Hours/BeforeBRScript.js b/Server-Side Components/Business Rules/Prevent Duplicate Incident Creation within 24 Hours/BeforeBRScript.js new file mode 100644 index 0000000000..240b2b7084 --- /dev/null +++ b/Server-Side Components/Business Rules/Prevent Duplicate Incident Creation within 24 Hours/BeforeBRScript.js @@ -0,0 +1,21 @@ +(function executeRule(current, previous /*null when async*/) { + + // Only run for active incidents + if (!current.caller_id || !current.short_description) + return; + + // Create a GlideRecord on the incident table + var gr = new GlideRecord('incident'); + gr.addQuery('caller_id', current.caller_id); // Same caller + gr.addQuery('short_description', current.short_description); // Same issue text + gr.addQuery('sys_created_on', '>=', gs.hoursAgoStart(24)); // Within last 24 hours + gr.addQuery('state', '!=', 7); // Exclude closed incidents + gr.query(); + + if (gr.next()) { + // Stop insert and show an error + gs.addErrorMessage("A similar incident has already been raised within the last 24 hours: " + gr.number); + current.setAbortAction(true); // Prevent record creation + } + +})(current, previous); diff --git a/Server-Side Components/Business Rules/Prevent Duplicate Incident Creation within 24 Hours/README.md b/Server-Side Components/Business Rules/Prevent Duplicate Incident Creation within 24 Hours/README.md new file mode 100644 index 0000000000..514aede035 --- /dev/null +++ b/Server-Side Components/Business Rules/Prevent Duplicate Incident Creation within 24 Hours/README.md @@ -0,0 +1,9 @@ +Prevent Duplicate Incident Creation within 24 Hours + +1. Write a Business Rule - Before Insert +2. Select the Incident Table +3. Only run/execute for all the active incidents +4. By Gliding the Incident Table will get the caller_id, short_description for checking the current caller and text provided for the short description +5. Querying the Incident Table as created within 24 Hours and excluding the closed incidents +6. Stop insert and show an error message +7. Prevent Incident record creation