We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to identify the operation for Async Business rule

String
Kilo Sage

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 

@Ankur Bawiskar 

 

 

(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);

3 REPLIES 3

Ankur Bawiskar
Tera Patron

@String 

I found few OOB business rules which are Async and current.operation() and it gives you the operation

 

AnkurBawiskar_0-1695215887570.png

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar  thanks for your quick reply ,but am getting current.operation() as null for Async

Is anything am missing ?

Please guide me 

@String 

the BRs I saw were OOB

Not sure if it works on any custom BR

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader