- 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 06:02 AM
@Souvick6917 Please share the name of your user field on Table_B and I will share the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 06:08 AM
Name of the field is 'users' and on checking the xml on the records of Table B, the field 'users' is showing display value along with sys_ids.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 06:14 AM
@Souvick6917 Please update your code as follows.
(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();
if (relatedRecord.next()) {
relatedRecord.deleteRecord();
gs.addInfoMessage("I am deleting records");
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 06:30 AM
@Sandeep Rajput Thank you for the code, one last thing,
The script is deleting records randomly, as for example initially I had 4 records and I try to add 1 more record, since the BR is on after update instead of adding it is deleting randomly. I have even set the order to 10000. The deletion should be done only when some records are deleted from Table A, not in insert or adding records.
Can you please help on this, as this is something I am trying for long.
Regards
Souvick

- 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.