Attachment verification for Catalog Items

Russell Abbott
Kilo Sage

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!

6 REPLIES 6

Timothy Onyskin
Tera Contributor

This is funny.  We got some items on our System Health scan from ServiceNow that said we should not be using "document" so when we try to check for attachments on a catalog item on submission, we use that.  I have not found a good way to check for an attachment in a scoped application on the desktop.  Anyone have any insight (ServiceNow code and KBs all say to use "document" which I guess now is against best practices)?

I would not change what you're currently doing. OOTB uses 'document' so until they change their method in some way for OOTB, that's the one we chose to go with.