- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Handling separate actions for "Create" and "Update" operations using the Flow Designer trigger "Record is Created or Updated":
This approach can be used as an alternative to current.operation()
when a Business Rule has both "Insert" and "Update" options selected.
Sample Use Case: Create a problem record when an incident is created and update the work notes of the same problem record when incident is updated
Business Rule Approach :
-
Table: Incident
-
When: After
-
Insert: ✅
-
Update: ✅
if (current.operation() == 'insert') {
// Create Problem record
var problemGr = new GlideRecord('problem');
problemGr.initialize();
problemGr.short_description = 'Auto-created from Incident: ' + current.number;
problemGr.description = current.description;
problemGr.correlation_id = current.getValue("number");
problemGr.insert();
current.problem_id = problemGr.sys_id;
}
else if (current.operation() == 'update' && current.problem_id) {
// Update work notes on the related Problem
var linkedProblem = new GlideRecord('problem');
if (linkedProblem.get(current.problem_id)) {
linkedProblem.work_notes = 'Incident ' + current.number + ' was updated.';
linkedProblem.update();
}
}
Flow Approach :
We’ll be leveraging the sys_mod_count
field—labeled as "Updates"—to determine whether the operation is an insert or an update.
If sys_mod_count
= 0, it indicates the record is being inserted (created).
If sys_mod_count
> 0, it signifies the record is being updated.
Identifying the "Insert/Create" Operation & executing the activities:
Identifying the "Update" Operation & executing the activities:
Thanks & Regards,
Subham Kumar Shaw
ServiceNow Architect/Consultant
ServiceNow Community Rising Star ' 2022/2023/2024
- 673 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.