Restrict Delete Action in Related List "Actions on selected rows..."

y-allen
Tera Contributor

Hello.

I am attempting to restrict the ability for users to delete attachments via the attachments related list on a record, when the record status is "Completed". The record is a part of a custom application in which users are allowed to upload and delete documents as necessary to complete the actions in the record. However, when the status is changed to Completed, I want to remove their ability to delete any uploaded items.

 

I attempted this using an ACL on the attachments table, but it appears that conditions and scripts are not allowed when the table name and application name are different. Also, using name "sys_attachment" and application Global while using a script to set the "answer" was usuccessful as well. 

 

I also right-clicked on the related list to review available options there, but nothing that implied I could script out conditions under which the Delete option would or would not be available.

 

yallen_0-1729879530776.png

 

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

The Delete UI Action has a condition to check if the user canDelete, which will refer to ACLs on the sys_attachment table, but really in this case you want to check a field on the parent record, so you could try to add to this condition something like

 

&&parent.status!='completed'

 

where 'status' is the name of the field on the custom application record, and 'completed' is the value of the choice, so update that as needed.  This would be on the UI Action named 'Delete' where Table = Global, unless you have a copy for sys_attachment in your instance, and List action = true.  There should only be one of those records. 

 

Brad, thank you for your reply. I assume this would affect the delete functionality across forms that have attachment as a related list. Would it be better to create a UI action on the sys_attachment table that I could modify so that the condition only applies to those custom records from the custom table?

 

Thanks again!

Yes!  Sorry, I usually start with that.  In this case you would be modifying the Delete button on EVERY related list.  Since your condition will be using a custom field and value it probably won't affect the other lists, but better to know for sure.  You can insert and stay on the UI Action record after changing the Table name to sys_attachment, and maybe temporarily give it a unique name so you can see the new button on the form to know you're updating the right record.  This would still affect every Attachment related list, so the full new condition would be more like:

current.canDelete()&&(parent.getTableName()=='scope.table_name'&&parent.status!='completed')||parent.getTableName()!='scope.table_name'

 

Sumanth16
Kilo Patron

Hi @y-allen ,

 

 

I would recommend using ACL approach so that no new UI action is to be created

1) visit this ACL

URL: https://instanceName.service-now.com/nav_to.do?uri=sys_security_acl.do?sys_id=80dfc5fec0a801664e82539cfb7a0bfb

2) advanced checkbox as true

3) script below

answer = getValue();

function getValue(){

	if(current.change_request.type == 'standard')
		return false;
	else
		return true;

}

Sumanth16_0-1729882234375.png

 

Please hit like and mark my response as correct if that helps.


Regards,

Sumanth Meda