- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi,
I have 2 business rule one is on Before update and another is on After insert and update.
1. Before Update BR:
- Condition : State = On Hold && Sub state = Customer && Additional Comment CHANGES
-
if (current.requested_for == gs.getUserID()) //if comment is updated by same as user in requested for
{
current.pending_target_date = chaging to NULL
current.substate = changing to NULL
current.state = WIP
fire an event (event 1)
}
2. After insert/update BR :
Condition : Additional Comment CHANGES
if (previous.state == 'On Hold' && current.state == 'WIP' && current.requested_for == gs.getUserID()) {
gs.info(' CONDITION PASSED');
return;
}
else { // for updates on comments
gs.info('RUNNING TWICE');
Fire Event 2
}
But when RITM state is On Hold and User( requested for) does and update.
BR1 runs successfully fires event 1 and BR2 runs Twice , Firstly i see 1st log statement "CONDITION PASSED" and 2nd Log statement "RUNNING TWICE". and Fires Event 2 which is not ideal. as i want to suppress the BR2 completely when BR1 is running .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
1 before update business rule on RITM Table and you should be good
Script: Ensure you give correct state, substate value in script
// Combined business rule for On Hold → WIP with comment logic
if (current.state == 'On Hold' && current.substate == 'Customer' && current.additional_comments.changes() && current.requested_for == gs.getUserID()) {
// Comment is being made by requested_for user
current.pending_target_date = null;
current.substate = '';
current.state = 'WIP';
// Fire Event 1 (custom event)
gs.eventQueue('event1_name', current, current.sys_id, gs.getUserID());
} else if (current.additional_comments.changes()) {
// Handle comment updates not matching above condition
// Fire Event 2 (custom event)
gs.eventQueue('event2_name', current, current.sys_id, gs.getUserID());
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Why do you have two BRs for this? The first rule is setting the conditions for the second rule to trigger. This could all be done in one BR.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
have some additional conditions in 2nd BR for some specific catalogs and and BR1 is open to all .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
you can combine and have extra check in the BR so that the additional logic only runs when your specific conditions meet.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
1 before update business rule on RITM Table and you should be good
Script: Ensure you give correct state, substate value in script
// Combined business rule for On Hold → WIP with comment logic
if (current.state == 'On Hold' && current.substate == 'Customer' && current.additional_comments.changes() && current.requested_for == gs.getUserID()) {
// Comment is being made by requested_for user
current.pending_target_date = null;
current.substate = '';
current.state = 'WIP';
// Fire Event 1 (custom event)
gs.eventQueue('event1_name', current, current.sys_id, gs.getUserID());
} else if (current.additional_comments.changes()) {
// Handle comment updates not matching above condition
// Fire Event 2 (custom event)
gs.eventQueue('event2_name', current, current.sys_id, gs.getUserID());
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader