Business rule generating duplicate event entries
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 04:32 AM
I'm trying to generate emails based on the below business rules that will trigger two events:
I'm using the below script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 06:36 AM
Summary
The duplicate events issue stems from an After Update Business Rule that queues emails twice: once because in-memory arrays reset on each execution, and again if another script calls current.update(), retriggering the rule (ServiceNow)(ServiceNow). Replacing array-based tracking with a GlideRecord query against Event [sysevent] ensures idempotency by checking for existing events before queuing new ones (ServiceNow). As a no-code alternative, configure two out-of-the-box Notifications on the same table to fire on state change, which inherently prevents duplicate sends per transition (ServiceNow)(ServiceNow).
Problem Identification
Arrays reset per execution: The original script uses processedEmails and processedSysIds arrays that are reinitialized on every BR run, so they don’t persist between invocations (ServiceNow).
Recursive BR firing: A call to current.update() elsewhere can cause the rule to execute twice for the same record, duplicating events (ServiceNow)(support.servicenow.com).
Missing state-change guard: Without using current.state.changesTo('pending_recertification'), events fire on both initial load and subsequent updates (ServiceNow).
Proposed Solutions
1. Code-Based GlideRecord Deduplication
Business Rule Setup
Table: x_lbg_group_recert
When: After → Update
Condition: state.changesTo('pending_recertification') (ServiceNow)(ServiceNow)
Script
(function executeRule(current, previous) { function triggerEvent(name, email, mgr) { var gr = new GlideRecord('sysevent'); gr.addQuery('name', name); gr.addQuery('instance', current.sys_id); gr.addQuery('parm1', email); gr.query(); if (!gr.next()) { gs.eventQueue(name, current, email, mgr); } } if (current.state.changesTo('pending_recertification')) { triggerEvent( 'x_lbg_group_recert.lbg.group.recert.grou', current.group_manager.email, current.group_manager ); triggerEvent( 'x_lbg_group_recert.lbg.group.recert.line', current.group_manager.manager.email, current.group_manager.manager ); } })(current, previous);
Best Practices & Notes
Avoid current.update() in After BRs to prevent recursion (ServiceNow).
No arrays: GlideRecord checks guarantee one event per record per manager (ServiceNow).
2. No-Code OOTB Notifications
Notification 1
Table: x_lbg_group_recert
Trigger: When “State changes to pending_recertification”
Recipient: Group Manager (group_manager)
Notification 2
Same trigger conditions
Recipient: Line Manager (group_manager.manager)
Advantages
Zero scripting required; built-in engine prevents duplicate sends per transition (ServiceNow).
Easily visible and maintainable via the UI (ServiceNow).
Testing
Change a record’s state to pending_recertification in a sub-production instance.
Code-Based: Verify exactly two entries in Event [sysevent] matching your instance and parm1 values.
Notifications: Confirm two emails—one to each manager—are sent only once per transition.
Sources
Business rule generating duplicate event entries – ServiceNow Community – Describes the original duplicate email triggers (ServiceNow)
Duplicate CI Monitoring records – ServiceNow Community – Explains BR firing twice due to current.update() (ServiceNow)
How to prevent duplicate user records – ServiceNow Community – Demonstrates GlideRecord dedup in BR (ServiceNow)
Double update occurs in Inbound Actions – ServiceNow Support KB0824467 – Highlights recursion from multiple updates (support.servicenow.com)
Avoid duplicate entry by BR – ServiceNow Community – Confirms GlideRecord check approach (ServiceNow)
changesTo() function not working – ServiceNow Community – Validates proper changesTo usage (ServiceNow)
Using current.update() in After BR – ServiceNow Community – Advises against current.update() in After BRs (ServiceNow)
Business Rules Technical Best Practices – ServiceNow Developers – Recommends idempotent script design (Developer Portal)
Notifications reference – ServiceNow Documentation – How to configure Notifications for record changes (ServiceNow)
Create custom notifications – ServiceNow Documentation – No-code setup for Notifications after record changes (ServiceNow)
Please mark this as the correct answer! 😊