- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2025 12:48 PM
I used the gsSCAttachmentCount() function in a client script for the Service Portal. We recently switched over to the Employee center and the same client script catalog client script is not working for our catalog items that have attachments required. Is there a way to extend the gsSCAttachmentCount() function to make it available for employee center?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 08:10 AM
Step 3 resolved the issue. I had to update the JS include related list to include the "GlobalCatalogItemsFunction" for the Employee Center portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 03:29 AM
Hi @Jewell_Aubert ,
You can do something like below to make attachment mandatory on portal.
function onSubmit() {
// Retrieve elements with the 'get-attachment' class using the document object
var attachmentElements = this.document.getElementsByClassName('get-attachment');
// Check if there are any attachment elements
if (attachmentElements.length === 0) {
// If no attachments are found, alert the user with a message and prevent submission
alert("You must attach at lease one Document.");
return false; // Block form submission
}
// If attachments exist, allow the form to be submitted
return true;
}
Check this blog for more explanation: https://servicenowwithrunjay.com/prevent-catalog-item-submission-if-there-is-no-attachment/
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 06:01 AM
Can I do this using a UI Script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 04:00 AM
use this so that it works in both native AND portal
function onSubmit() {
//Type appropriate comment here, and begin script below
try {
if (window == null) {
// portal
if (this.document.getElementsByClassName('get-attachment').length == 0) {
alert('You must add attachment before submitting this request.');
return false;
}
}
} catch (ex) {
// native view
var length = getSCAttachmentCount();
if (length == 0) {
alert('You must add attachment before submitting this request.');
return false;
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 08:10 AM
Step 3 resolved the issue. I had to update the JS include related list to include the "GlobalCatalogItemsFunction" for the Employee Center portal.