Attachments in ServiceCatalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello All
I have been working on restricting the number of attachments to be added on a catalog form. You may ask to use three variables with type 'Attachment', but it does not look good or give a good interface.
So, I developed a catalog script of 'onSubmit', attaching below.
But the issue is this shows a infoMessage: This catalog client script is not VA supported due to the presence of the following variables in the script: this.document.getElementsByClassName.length.
Even tried with g_form.getAttachments(), same.
function onSubmit() {
//Type appropriate comment here, and begin script below
var attacha = this.document.getElementsByClassName('get-attachment').length;
//var attacha = g_form.getAttachments();
if(attacha>3)
{
g_form.addErrorMessage('Maximum number of attachments is 3');
return false;
}
return true;
}
Would appreciate if we have any workaround which can solve this by Catalog client script itself.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
this should work in both native and portal
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 > 3) {
g_form.addErrorMessage('Maximum number of attachments is 3');
return false;
}
}
} catch (ex) {
// native view
var length = getSCAttachmentCount();
if (length > 3) {
g_form.addErrorMessage('Maximum number of attachments is 3');
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
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
3 weeks ago
Your Client Script needs to call a Script Include via GlideAjax. The SI can count the number of attachments and return a value to be evaluated by the Client Script to determine if the error message should be displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago