The CreatorCon Call for Content is officially open! Get started here.

Help with script to hide attachments section in header on form

Marcel H_
Tera Guru

I have a requirement to hide the attachments in the header of a form, as well as the attachment icon (paperclip) when the form loads, and the user isn't a member of a specific group. I already have the group membership portion working to hide form sections and related lists but haven't been able to get the actual attachments to hide. I created a new script just for to see if I can hide the attachments, but still no luck.

 

Here is what I have currently, which is hiding the paperclip icon as expected, but the actual attachments are still shown. Isolate script in unchecked.

function onLoad() {

g_form.disableAttachments();
document.getElementById('header_attachment').style.display = 'none';
document.getElementById('header_attachment_line').style.display = 'none';

}

 

When loading form attachments are still displayed, but paperclip is hidden:

MarcelH__0-1734482878434.png

 

10 REPLIES 10

Thankfully we are just about ready to upgrade the rest of the instances as well, so that this shouldn't be an issue any longer,

 

I did rebuild the ACL directly in the test environment, but it still doesn't work correctly, so I will likely just wait until Xanadu to implement. Thanks!

Abhay Kumar1
Giga Sage

@Marcel H_ Try this explaining how you can hide and yes dom does not support and you can be in a situation when it would work as admin but for not end user so avoid this.

https://youtu.be/Zt4KynJanj0?si=s4F9-kCZZzafLmSe 

Ankur Bawiskar
Tera Patron
Tera Patron

@Marcel H_ 

you are using DOM manipulation which is not recommended

your script will work fine if Isolate Script = False for your onLoad client script

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar I would like to control this without DOM manipulation, but I don't think that's possible, correct? Unfortunately, even when making sure that Isolate Script = False the actual attachments aren't hidden, only the attachment icon. Any idea what would cause that script not to work as written?

@Marcel H_ 

it should work and it worked for me

document.getElementById('header_attachment').style.display = 'none';
document.getElementById('header_attachment_line').style.display = 'none';

If my response helped please mark it correct and close the thread so that it benefits future readers.

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