
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
04-21-2019 08:02 AM - edited 08-10-2024 08:15 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
A short article to share gained knowledge about hiding attachments and making attachments mandatory for Catalog Items on the Service Portal. Sharing this because numerous times threads with questions about hiding attachments or making attachments mandatory are coming by.
Pre-Madrid
Pre-Madrid, we could script this thru Catalog Client Scripts. Another option would be to customize the SC Catalog Item widget. Both not great, the Catalog Client Scripts are needed on every Catalog Item you wish to have this functionality on, customizing the SC Catalog Item would mean you would miss updates from patches/upgrades.
For if you are not yet on Madrid and do want to hide attachments or make attachments mandatory. Here is some example scripting.
Hide attachment - onLoad Catalog Client Script
function onLoad() {
var attachmentButton = top.document.getElementsByTagName('sp-attachment-button');
attachmentButton[0].parentNode.hidden = true;
}
Mandatory attachment - onSubmit Catalog Client Script
function onSubmit() {
if(this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('mandatory_attachment'));
return false;
}
}
Madrid
With Madrid, some cool and super easy checkboxes are introduced! Checkboxes which can be configured for Catalog Items individually and making scripts like above obsolete.
Madrid checkboxes
---
And that's it actually. Hope you like it. If any questions or remarks, let me know!
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group
---
- 13,090 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
One addition. If you are using a clone of the SC Catalog Item widget [widget-sc-cat-item-v2], then, unfortunately, this will not work. The out-of-the-box SC Catalog Item has been updated with code like:
Body HTML Template
ng-if="c.showAttachments()"
Client Controller
c.showAttachments = function() {
return !$scope.submitted &&
!c.data.sc_cat_item.no_attachments &&
c.data.sc_cat_item.sys_class_name !== "std_change_record_producer";
}
So interested in this new addition from Madrid, update your cloned widget.
Kind regards,
Mark
---

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
In my case for attachments and I'm sure other a check box with attachment mandatory would not work. In my current environment attachments are mandatory base on variable choices. For example, on one of my forms it could have anywhere between 0 - 4 attachments mandatory. It would be nice if they add a drop down with "Always Mandatory" and "Condition Base". Then if you choose condition based you would choose under what conditions attachments are mandatory. Although thinking about it that might not necessary meet number of attachments unless there was a filed for that as well.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I need conditional control of attachments based on field values, which I would ordinarily use a catalog client script to configure.
Can you advise if I need the attachments to be visible based on field selection?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Brian, did you find any way to achieve your desired results?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hide attachment check box is inactivated by system in our instance, what would be the issue.
I couldnt see the field in list or form even after making it active.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
How to achieve mandatory attachment before submitting a workspace form?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mark,
Your client script - onLoad is working. Thanks
function onLoad() {
var attachmentButton = top.document.getElementsByTagName('sp-attachment-button');
attachmentButton[0].parentNode.hidden = true;
I tried to use the same script for onChange catalog client script but it is not working as expected when I change a value of a field. Please advise. Thanks

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Tang Please share details, without no one can help you. Or better: create a new question on the community and provide as much as info that you can.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mark,
Here is the form
On the form itself, the field "Suspect an email ccontains MALICIOUS CONTENT?" only have two options i.e. either Yes or No. If a user select the option Yes, then the paper clip Add attachments should be hide. However, it is not working as expected.
Here is the onChange catalog client script. Please advise. Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mark,
Here is the catalog client scripts onChange
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mark,
I am not sure why it was not get uploaded. Let me try it again. Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Please ignore my previous question. All sorted. Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Mark Roethof how to make attachment visible for some condtion