How to prevent to submit if Attachment is not attached in a catalog
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 01:07 AM
Please provide script for how to prevent a catalog to submit without attachment using GlideAjax
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 01:13 AM
if you are referring to catalog item then use this and it will work in both native + portal without glideajax
function onSubmit() {
//Type appropriate comment here, and begin script below
try {
var count = getRPAttachmentCount();
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;
}
}
}
function getRPAttachmentCount() {
var length;
try {
length = angular.element("#sc_cat_item_producer").scope().attachments.length;
} catch (e) {
length = -1;
}
return length;
}
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
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader