Getting an error - Submit canceled due to a script error - please contact your system administrator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2023 09:33 AM
Hi all,
I have a catalog item, where if the option "Add" is selected, the attachment field becomes mandatory and the user gets a pop-up to attach a document. This seems to be working fine on the Service Portal but not working on the backend. I put in a HI ticket but the engineer said this is a custom script and needs to be looked at internally.
This is the script for the catalog item.
function onSubmit(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var countRequired = 1;
if(window == null){
// portal
var choice = g_form.getValue('identify_the_type_of_epic_payer_plan_change_being_requested');
if (choice == 'Add')
if(this.document.getElementsByClassName('get-attachment').length != countRequired) {
alert('You must add attachments before submitting this request.');
return false;
}
}
else{
// native view
var length = $j("li.attachment_list_items").find("span").length;
if(length != countRequired){
alert('You must add attachments before submitting this request.');
return false;
}
}
}
Please find the screenshot attached for the error as an administrator and an ITIL user.
Any help would be appreciated.
Thanks,
Mallika

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2023 11:12 AM
Why not using "Attachment" variable to obtain attachment from the user?
You can make Attachment variable visible when option "Add" is selected by using UI Policy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2023 11:25 AM
Hi, based on the details provided IE the screenshot error code referencing 'document' I suspect the issue is your DOM manipulation. Is the 'Isolate script' field set correctly for your script?
Client scripts (servicenow.com)
Also DOM manipulation is not recommended best practice as DOM can change, and I would suggest replacing the DOM reference with a Glide Ajax call to look-up and validate the existence of any attachment.
See option 5 of this article
Possible Ways for Making an Attachment Mandatory :... - ServiceNow Community