Disable renaming or delete/remove attachment option for a table

Community Alums
Not applicable

Hi All,

I have a requirement that "only the user who attached that attachment should be able to rename the attachment or delete/remove the attachment others shouldn't" for a particular table(custom table).

@Ankur Bawiskar Any idea?

 

Thanks,

Bala

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can try to use before update BR on sys_attachment and check if the logged in user is the created by of that sys_attachment

For Remove/Delete ensure you have correct table level DELETE ACL

Actually both your requirements can be handled via before update/delete business rule

BR: sys_attachment

Before Update AND Delete

Condition: current.table_name == 'incident'

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if(gs.getUserName() != current.sys_created_by){
		gs.addErrorMessage("You are not allowed to update/delete the file as you are not the one who attached it");
		current.setAbortAction(true);
	}

})(current, previous);

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Chandu Telu
Tera Guru
Tera Guru

Hi Balaraju,

 

Check the below link to hide the rename option you can check the current user and method in below link will hide the Rename Option but it's best practice 

 

https://community.servicenow.com/community?id=community_question&sys_id=a823c3e1dbd8dbc01dcaf3231f961956

 

Thanks
Chandu Telu
Please Mark Correct/helpful, if applicable,

Community Alums
Not applicable

@Chandu Telu thsanks for replying and this won't solve my requirement

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can try to use before update BR on sys_attachment and check if the logged in user is the created by of that sys_attachment

For Remove/Delete ensure you have correct table level DELETE ACL

Actually both your requirements can be handled via before update/delete business rule

BR: sys_attachment

Before Update AND Delete

Condition: current.table_name == 'incident'

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if(gs.getUserName() != current.sys_created_by){
		gs.addErrorMessage("You are not allowed to update/delete the file as you are not the one who attached it");
		current.setAbortAction(true);
	}

})(current, previous);

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Community Alums
Not applicable

Hi @Ankur Bawiskar Everything is fine but SetAbortAction is not working since we are working in scoped application

Is there any other way to abort?