Stop a business rule when an update is done to the backend record through workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 06:06 AM
Hi,
I need to stop processing the business rule when an update is done to the back-end record through workflow.
When a request(RITM) is submitted to update a record value from the record producer the workflow is triggered to updated the record on the backend. We have a business rule written to create logs on a custom table when a record is updated, So even when a user updates the table record a log is created and when a request is submitted also a log is created. But we need to create records on when a workflow is triggered or when a user manually updates the record.
I tried using gs.getSession().isInteractive() but returns true for both of the above cases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 01:39 AM
Hi @Ankur Bawiskar, Do we have any update on this? Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 01:51 AM
I am not sure why the duplicate records are getting created.
Are you sure the same record is not getting updated multiple times?
what's the script inside the BR?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2023 07:52 AM
@Ankur Bawiskar
Please find the records in the below snapshot.
One of the record is created on submission of the RITM through workflow and other record is created by the business rule. Because the request (RITM) submitted is for change of Description
1. Record is created on submission of the RITM through workflow.
2. Other record is created by the business rule as per the condition on the business rule. Refer below snapshot
Business rule:
gs.sleep(30000);
var cl = new GlideRecord('change_log');
cl.addQuery('u_name_of_field_updated', field);
cl.addQuery('u_old_value', oldValue);
cl.addQuery('u_taxonomy_layer', layer);
cl.addQuery('u_new_value', newValue);
cl.addQuery('u_change_type', changeType);
cl.addQuery('u_division', taxonomy_node);
cl.query();
if (cl.next()) {
new getDivRole().createChangeLog(ritm, openBy, openAt, field, oldValue, layer, approved, approver, newValue, changeType, taxonomy_node, sub_change_type, div, family, product, feature); // Script Include will create records on the change log table
}
The above script should not execute as there is already a record created on the change log table through the RITM - workflow. It should validate and stop the business rule as there is already a record created on the change log table.
gs.sleep(30000); doesn't seems to be working on the business rule.