Attachment verification for Catalog Items
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 09:56 AM
It has been recommended to look into the script that we use to validate an attachment on a Catalog Item submitted both in Portal and ITIL views. Here's the script in question
function onSubmit() {
var vpn_form = g_form.getValue('vpn_form_completed_standard_form');
if(vpn_form == 'Yes'){
//Works for native view
try {
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('You may be missing an attachment, please attach and resubmit');
return false;
}
}
//For Service Portal
catch(e) {
var count = getSCAttachmentCount();
if(count <= 0) {
alert('You may be missing an attachment, please attach and resubmit');
return false;
}
}
}
else if (vpn_form == 'No'){
alert('Please select YES for the variable VPN Form Completed : Standard Form, attach and resubmit');
return false;
}
}
It has been suggested to set Isolate to True, and to remove getElementByID and getSCAttachmentCount.
I found a way to remove getElementByID but not getSCAttachmentCount.
As far as I can see, not Isolating is necessary here.
Is there another way to validate an attachment on both Portal AND Itil without that?
Thank you in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 11:00 AM
I believe it is only getElementByID that requires Isolate to be true. I'm curious what was the reason for the recommendation to look at the script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 01:19 PM
Sorry, you are correct. It was in reference to getElementByID. A 3rd party suggests that "Trying to use them in Catalog Client Scripts where the UI Type is not "Desktop" may result in run time errors. It is recommended not to use jQuery, PrototypeJS, gel and other techniques"
Note, I don't have any issues with the script as it stands, these are suggestions for best practice from a 3rd party analysis.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 03:18 PM
That is true that this is best practice. Sometimes you cannot avoid using these things like in this situation. I use this same script for several catalog items. I love how these analysts make suggestions but don't give you anything on how to do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 07:40 PM
Completely understand, I couldn't find another efficient way to handle this, so that makes sense. I appreciate your feedback!