- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 05:10 AM
Hello All,
I have 2 tables, Table A and Table B. On Table A, I have a glide list field for users and the related table is Table B. When users are added on the field , same user is added on Table B. Now I want to have delete functionality from Table A on Table B . When I remove users from the glidelist field on Table A, the same should be removed from Table B. The related records are fetched from Table B.
Below is my business rule:
The business rule running on Table A.
When to Run : After, Delete checkbox checked
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 06:35 AM
@Souvick6917 This is expected as Users is a Glide list field on Table_B and multiple records may contain the same sys_jds hence the deletion is random. If you wish to delete all the records then you can try the following.
(function executeRule(current, previous /*null when async*/ ) {
var glideListArray = current.getValue('user').split(',');
gs.info('Souvick glide 1 :' +glideListArray); // This log is not getting registered even
for (var i = 0; i < glideListArray.length; i++) { // The delete operation is doing nothing, the records are removed from Table A glidelist field, but staying on the Table B
var relatedRecord = new GlideRecord('Table_B');
relatedRecord.addQuery('users','CONTAINS',glideListArray[i])
relatedRecord.query();
while (relatedRecord.next()) {
relatedRecord.deleteRecord();
gs.addInfoMessage("I am deleting records");
}
}
})(current, previous);
Please mark my responses helpful and accepted solution as I already addressed all of your issues.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 07:55 AM
@Souvick6917 Hmm, because there could be many such rows on Table_B where the same user sys_id is present. The easiest way to address this is to have a reference of Table_A as a column on Table_B. This way you can filter the exact record using Table_A's sys_id and random deletion wouldn't be an issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 05:40 AM
Hi @Souvick6917
current.getValue('user').split(',');
-> this fetches current values of GlideList, which after deletion would likely be an empty and due to that you not getting anything here.
As Sandeep suggested you should write 'After Update' BR on table A. Where you can compare 'current' and 'previous' GlideList and delete records accordingly from Table B.
Also, add a condition if necessary to restrict when this rule should run (e.g., only when the GlideList field changes).
i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
rajesh