How to restrict user to delete records when related lists is not empty ?

venugopal s
Tera Contributor

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

venugopals_0-1680851522273.png

 

@Ankur Bawiskar 

12 REPLIES 12

Sandeep Rajput
Tera Patron
Tera Patron

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.

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

AnveshKumar M
Tera Sage
Tera Sage

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

Thanks,
Anvesh

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