How can you require attachments on a catalog item in the Service Portal (SP)?
Unfortunately you can't just use the Client Script you used in the old CMS site right? The old DOM manipulation scripts used in CMS often won't work in the SP. as it is a different architecture than CMS.
How to require attachments in SP
1. Add a UI Script
- In the Left Navigator Bar, go to System UI > UI Scripts
- Click New
UI Script: GlobalCatalogItemFunctions
Global: true
Script:
function getSCAttachmentCount() {
var length;
try {
length = angular.element("#sc_cat_item").scope().attachments.length;
} catch(e) {
length = -1;
}
return length;
}
2. Add a JS Theme

- In the Left Navigator Bar, go to Service Portal > Portals
- Click the Portal you want to adjust. It maybe be the one with URL suffix of "sp".
- Click the "info" button for the Theme. The standard theme is "Stock"
- Add your JS Include there
Create New JS Theme
Display Name: GlobalCatalogItemFunctions
UI Script: GlobalCatalogItemFunctions
3. Create a Catalog Client Script
For your catalog item you want to require attachments, use this client script.
function onSubmit() {
//Works in non-portal ui
try {
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('You must attach the completed form before submitting this request.');
return false;
}
}
//For Service Portal
catch(e) {
var count = getSCAttachmentCount();
if(count <= 0) {
alert('You must attach the completed form before submitting this request.');
return false;
}
}
}