How to identify the operation for Async Business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 05:54 AM - edited 09-20-2023 06:06 AM
Hi Team ,
Am using the below Async Business rule to get the Sys_id's of records when inserted or deleted
code is executed(getting the log "Entering the BR"). But not getting the sys_id ,Please guide me the best pratices
(function executeAsyncRule(current, previous /*if deleted*/) {
// Check if the operation is an insert or delete
if (current.operation() == 'insert' || current.operation() == 'delete') {
// Initialize an array to store sys_ids
var sysIds = [];
if (current.operation() == 'insert' && current.size() > 1) {
// Loop through the inserted records and capture their sys_ids
for (var i = 0; i < current.size(); i++) {
sysIds.push(current[i].sys_id);
}
} else if (current.operation() == 'delete' && previous.size() > 1) {
// Loop through the deleted records and capture their sys_ids
for (var i = 0; i < previous.size(); i++) {
sysIds.push(previous[i].sys_id);
}
} else {
// If only one record is inserted or deleted, capture its sys_id
sysIds.push(current.sys_id);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 06:18 AM
I found few OOB business rules which are Async and current.operation() and it gives you the operation
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
09-20-2023 06:42 AM
Hi @Ankur Bawiskar thanks for your quick reply ,but am getting current.operation() as null for Async
Is anything am missing ?
Please guide me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 06:45 AM
the BRs I saw were OOB
Not sure if it works on any custom BR
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader