Service Portal Catalog Items: Hide Attachment / Mandatory Attachment [Madrid]
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!
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group---
https://www.servicenow.com/community/developer-articles/service-portal-catalog-items-hide-attachment-mandatory/ta-p/2307752
