Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

g_form.disableAttachments() caused "Download all" button to disappear

Colleen
Tera Expert

We have a requirement to allow users to update and ast_contract record but not attach documents.

 

I created a deny unless access control rule to prevent users without the custom supplier_manager role from creating an attachment on an ast_contract record.

 

However, even if the user does not have permission to create an attachment on the record, the paperclip icon on the form and the Choose file button on the Attachments form are still visible. If a user without the supplier_manager role clicks the paperclip icon or "Choose file", they are prompted to select a document etc., but it is not attached to the ast_contract record.  As that would be confusing for the user, I put g_form.disableAttachments() into an onLoad client script to hide the paperclip icon and "choose file" buttons. However, the "Download All" button disappeared from the Attachments form as well.

Colleen_1-1777473279847.png

 

I was able to hide the paperclip icon using CSS in the onLoad client script, but cannot figure out how to hide the "choose file" button.

 

Is there a way to hide the paperclip icon and "Choose file" button without losing the "Download All" functionality?

 

 

 

6 REPLIES 6

Vishal Jaswal
Giga Sage

Hello @Colleen 

For native UI, below is an onLoad Client Script:

21.jpg22.jpg
For Service Catalog, please refer to KB article: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0723065 


Hope that helps!

Hi Vishal

I already tried that code. It hides the paperclip icon, but not the "Choose files" button. Also, the code had to be embedded in a setTimeout function for it to work.

Hello @Colleen 

With below sample onLoad Client script code, you can hide button(s) on the native UI form:

// Hide Save, Update and Submit UI Actions (buttons) --> Reference: https://stackoverflow.com/questions/43452670/hide-save-button-on-asset-form
    var items = $$('BUTTON').each(function(item) {
        if (item.innerHTML.indexOf('Save') > -1) {
            item.hide();
        }
    });

    var items1 = $$('BUTTON').each(function(item1) {
        if (item1.innerHTML.indexOf('Update') > -1) {
            item1.hide();
        }
    });

    var items2 = $$('BUTTON').each(function(item2) {
        if (item2.innerHTML.indexOf('Submit') > -1) {
            item2.hide();
        }
    });

Reference: https://stackoverflow.com/questions/43452670/hide-save-button-on-asset-form 


Hope that helps!

Hi Vishal

It would not be possible to hide the 'choose files' button in an onLoad script since the attachment form is loaded when "Manage Attachments" or the paperclip icon is clicked.