How to restrict user to delete records when related lists is not empty ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 12:13 AM - edited 04-11-2023 03:59 AM
Hi Everyone,
I have written delete ACL on cmn_location where class is not Workplace Location, but I need to add condition when Associated tables have any records then deletion rule should not be applicable.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 12:45 AM
In the script field of ACL, make a GlideAggregate Query to get count of records which are associated with current record in the related tables. If count is >0 in any of the associated tables then simply return answer=false; This will prevent users from deleting that record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 04:36 AM
Hi @Sandeep Rajput
Its need to be applicable on Users, CI, Network Subnet Locations, Circuits, Locations, Discovery Schedule tables and also delete button should not appear on location record.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 12:53 AM
Hi @venugopal s ,
You can use advanced ACL with script like the one below. For example you want to restrict deletion if the location have child locations (related locations), you can use script like the one below.
answer = canDelete();
function canDelete(){
var locGr = new GlideRecord('cmn_location');
locGr.addQuery('parent', current.sys_id);
locGr.next();
if(locGr.next()){
return false;
}else{
return true;
}
}
Similarly you can apply the same logic for other related list tables too.
Note: Make sure Admin Overrides flag is un-checked to make this ACL applicable for users with admin role.
Thanks,
Anvesh
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2023 04:21 AM - edited 04-07-2023 04:37 AM
Hi @AnveshKumar M ,
Its need to be applicable on Users, CI, Network Subnet Locations, Circuits, Locations, Discovery Schedule tables and also delete button should not appear on location record.
Thanks