Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Display error message when, removing attachment is not allowed.

Aman Thakur
Tera Contributor

Hello all,

I needed help in a requirement which involves showing an error message on INC table record when someone tries to remove an attachment on it and is not allowed to do so.

I tried a "Delete" BR on the "sys_attachment" table, but the error message does not appear on INC table (form view).

I guess it has something to do with "gs" object used in gs.errorMessage.

So wanted to know if it is possible to do this.

 

Thanks.

4 REPLIES 4

Sohail Khilji
Kilo Patron

Hi @Aman Thakur ,

 

1. You can try alternative ways like create an ACL that stops from deletion of attachment.

2. Try to Hide the X or delete button on Incident table to disallow attachment deletion on incident table.


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Runjay Patel
Giga Sage

Hi @Aman Thakur ,

 

You can use "g_form.disableAttachments();" to hide the paper icon based on your access.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Here in this Video, I have covered the Classifier and Process Classifier for Application Thank you for visiting my channel. Here, I'll share various technical knowledge. Feel free to reach out to me directly for any Service Now-related queries. Your support encourages me to consistently deliver ...

Aman Thakur
Tera Contributor

Thankyou @Runjay Patel & @Sohail Khilji , for your replies.

The Scenario: Users can remove only those attachments on INC record that were added by a particular group (let's say Group 1). So, only those attachments can be removed/deleted which were added by Group 1 members.

 

But based on your replies, can it be concluded that this cannot be achieved using BR and gs.errorMessage() method?

Because I could see the error messages on "sys_attachment" list view when I tried removing/deleting an attachment directly from Attachment table.

 

Thanks.

Hi @Aman Thakur ,

 

On that case you can use ajax call to check the user belong to group or not. if dont then use "g_form.disableAttachments();"

 

1. Create onload client script and use below code.

var ga = new GlideAjax('UserUtils');
    ga.addParam('sysparm_name', 'checkGroupUser');
    ga.addParam('sysparm_caller_sys_id', group_name);
    ga.getXML(hideAttachment);
    function hideAttachment(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        
        if (answer=='false') {
           g_form.disableAttachments();
        }

 

2. create script include and use below code.

var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    checkGroupUser: function() {
        var group= this.getParameter('sysparm_group_sys_id');
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('group',group);
gr.addQuery('user',gs.getUserID());
if(gr.next())
        return true;
else
return false;
    },


    type: 'UserUtils'
});

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Here in this Video, I have covered the Classifier and Process Classifier for Application Thank you for visiting my channel. Here, I'll share various technical knowledge. Feel free to reach out to me directly for any Service Now-related queries. Your support encourages me to consistently deliver ...