onSubmit script error: TypeError: Cannot read properties of null (reading 'value'):
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 07:20 AM
I am using a script to force adding an attachment to a request:
function onSubmit() {
var proof = gel('sysparm_item_guid').value;
//alert('proof'+proof);
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "sc_cart_item");
att.addQuery("table_sys_id", proof);
// att.addQuery("sys_created_by", g_user.userName);
// att.addQuery("sys_created_on", '>=', 'javascript:gs.minutesAgo(10)');
att.query();
if (!att.next()) {
alert("Please attach a .zip file to the request containing the project that will be promoted to production before submitting.");
return false;
}
return true;
}
When I try to close the request I get this error:
Error MessageonSubmit script error: TypeError: Cannot read properties of null (reading 'value'):
function onSubmit() {
var proof = gel('sysparm_item_guid').value;
//alert('proof'+proof);
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "sc_cart_item");
att.addQuery("table_sys_id", proof);
// att.addQuery("sys_created_by", g_user.userName);
// att.addQuery("sys_created_on", '>=', 'javascript:gs.minutesAgo(10)');
att.query();
if (!att.next()) {
alert("Please attach a .zip file to the request containing the project that will be promoted to production before submitting.");
return false;
}
return true;
}
This is not causing an error on other requests. I am not proficient in JS so I have no idea how to fix this. Any suggestions greatly appreciated.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 07:26 AM
Hi
Are you testing this in ServicePortal? Below code does not work in Service Portal
gel('sysparm_item_guid').value
Refer below URL to make attachment mandatory in Service Portal
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 07:28 AM
Hello
instead of this you can utillize "Mandatory attachment" check box in the catalog item form which will make attachment mandatory and throw the alert while you submit with out adding an attachment
Search for your item and make the mandatory attachment true
MARK MY ANSWER CORRECT IF IT HELPS YOU

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 07:29 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2022 07:29 AM