- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2019 06:58 AM
Dear all
We have a catalog item where a certain attachment is required for submit. To that effect a Client Script checking there's at least one attachment uploaded with the item, and it works a charm as long as the item is ordered as a stand alone item. However, when the item is added to an Order Guide, the script returns -1 regardless of number of attachments having been uploaded. Anyone has an idea? Please see the code below.
function onSubmit() {
//Works in non-portal ui DISREGARD THIS ONE
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.');
alert('In non-portal UI');
return false;
}
}
//For Service Portal THIS IS THE CASE BEING FIRED
catch(e) {
var count = getSCAttachmentCount();
if(count <= 0) {
alert('In Service Portal. Number of attachments: '+count); //Always returns -1 if item is in an order guide
alert('You must attach the completed form before submitting this request.');
return false;
}
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 04:38 AM
Hi Allen
Actually, with some aid from a valued colleague, we managed to get it to work with this very simple little code snippet:
function onSubmit() {
if(this.document.getElementsByClassName('get-attachment').length==0){
alert('You must attach the completed form before submitting this request.');
return false;
}
// alert("Yeeey, there's an attachment!");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2019 07:07 AM
Hi,
This is a known issue in the group that has been chatting about this and participating in using the code you have (where you most likely found that in another thread). Unfortunately, there is no fix at this time. What some have been doing is just trying to reinforce that an attachment is mandatory by creating infomessages/alerts and other things in hopes of the user attaching it.
This is the LONG thread where we've been talking about this: https://community.servicenow.com/community?id=community_question&sys_id=dd618729db98dbc01dcaf3231f96... if you scroll wayyyy down you'll see where me and another user talk about it not working for order guide and my suggestion there, just as I mentioned here, is what people seem to use.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 04:38 AM
Hi Allen
Actually, with some aid from a valued colleague, we managed to get it to work with this very simple little code snippet:
function onSubmit() {
if(this.document.getElementsByClassName('get-attachment').length==0){
alert('You must attach the completed form before submitting this request.');
return false;
}
// alert("Yeeey, there's an attachment!");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 07:20 AM
Hmm, ok. I'll test and see and if so, then that's a big win and I would say you should post that in that thread.
Now the attachment check (the one previously used) does work in order guide when it's only 1 item, does yours work with 2 or more? Again, I'll check, but just throwing that out there.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!