Business Rule Script - Find record and go to other table and delete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 02:03 AM
Hi All,
we have a table where master data are available. And we have another table where Bank Details are available. Both matching with the customer number.
Now we need a BR as follow: If the master data has the archive flag, the customer number should be determined via a script. Than in the same script should go to the other table where bank details are available. Based on the determined customer number, the bank details should be deleted in the bank table.
My script is not working:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 02:21 AM
Hello @BuriB
This seems to be duplicate question asked, please check my response over Business Rule to find a record in one table and th... - ServiceNow Community
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 02:49 AM
Hi @BuriB ,
Can we try following script:
(function executeRule(current, previous /*null when async*/) {
// Check if the archive flag is set
if (current.archive_flag == true) {
var customerNumber = current.customer_number;
var bankDetailsGR = new GlideRecord('x_bgbsg_mdm_bank_details');
bankDetailsGR.addQuery('customer_number', customerNumber);
bankDetailsGR.query();
while (bankDetailsGR.next()) {
bankDetailsGR.deleteRecord(); // This deletes the matching bank details record
}
gs.info('Bank details deleted for customer number: ' + customerNumber);
}
})(current, previous);