User should not able to delete attachment in change ticket after Scheduled state

Sangeeta_Nayak
Tera Contributor

Hi All,

 

I have a requirement to restrict users from deleting attachments in a change ticket once the state changes to "Scheduled." However, users should still be able to add attachments in any state.

I have implemented a before/delete Business Rule, but it is not showing any error. The system allows the user to delete the attachment, and after the page refreshes, the document reappears. This partial behavior is confusing for the user. Although the attachment is not actually deleted, there is no error message, and the user only realizes the attachment wasn't deleted after the page refreshes. However, after clicking the remove button, it appears as if the attachment was removed.

I am looking for an approach where, if the user tries to remove an attachment after the state is "Scheduled," the system will throw an error.

 

Thanks

2 ACCEPTED SOLUTIONS

Brian Lancaster
Tera Sage

Can you share your business rule? Was your business rule on the attachment table?

View solution in original post

I got an ACL to work. I had to modify an OOB ACL to get it to work. As you can see from the screenshot below it removes the checkboxes next the the attachments and the remove button is not visible.

BrianLancaster_0-1732300234795.png

The ACL I modified can be found here  https://[instance].service-now.com/nav_to.do?uri=sys_security_acl.do?sys_id=0c66472a0a0a0b82017c1f3df66a3fe7 
I added the following code right after var tableName = current.table_name;

 

//Handel change request files
    if (tableName == "change_request") {
        var changeRequest = new GlideRecord('change_request');
        if (changeRequest.get(current.getValue('table_sys_id'))) {
            if (changeRequest.state >= -2) //Value of "Scheduled" state
            {
                return false;
            } else {
                return true;
            }
        }
    }

 

 

View solution in original post

8 REPLIES 8

Brian Lancaster
Tera Sage

Can you share your business rule? Was your business rule on the attachment table?

Sangeeta_Nayak
Tera Contributor

Hi ,

 

I have implemented a before/delete Business Rule on the sys_attachment table.

The condition I have provided is: current.getValue('table_name') == 'change_request';

 

The script is as follows:

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

    // Add your code here
    var changeRequest = new GlideRecord('change_request');
    if (changeRequest.get(current.getValue('table_sys_id'))) {

        if (changeRequest.state >= -2) //Value of "Scheduled" state
        {
             gs.addErrorMessage('Attachments cannot be deleted for Change Requests in the Scheduled state or later.');
            current.setAbortAction(true);
        }
    }
})(current, previous);
 
Please let me know if any further modifications are needed.

Sangeeta_Nayak
Tera Contributor

Hi @Brian Lancaster ,

 

Please let me know if any further modifications are needed.

Just want to make sure you don't need any further help. I noticed that your marked my answer a correct.