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-11-2023 09:02 AM - edited 04-11-2023 09:04 AM
To add a condition to your delete ACL on cmn_location that prevents deletion when associated tables have records, you can modify your existing script to include a check for associated records. Here is an example script that includes this check:
// Get the current record being deleted var location = current; // Check if the location class is not Workplace Location if (location.getValue('sys_class_name') != 'cmn_location_workplace') { // Check if there are any associated records in the Location Association table var locationAssoc = new GlideRecord('cmn_location_association'); locationAssoc.addQuery('location', location.sys_id); locationAssoc.query(); if (locationAssoc.hasNext()) { // Cancel the delete if associated records exist gs.addErrorMessage('Associated records exist. Cannot delete location.'); current.setAbortAction(true); } }
In this script, we first get the current cmn_location record being deleted. We then check if the location class is not Workplace Location. If it is not, we then query the cmn_location_association table to check if there are any associated records for this location. If there are, we cancel the delete action and display an error message indicating that associated records exist.
You can modify this script to include additional checks for other associated tables as needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 12:13 AM
Hi
@DUGGI ,
It's getting multiple error messages based on associated records. how to restrict to single error message.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 02:03 AM
Hi @DUGGI ,
How can we hide delete button instead of error message.
Thanks