
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2020 06:07 AM
I have a catalog client script to make attachment mandatory based on conditions:
function onSubmit() {
//Get the field
var field= g_form.getValue("hr_process");
//Make attachment mandatory only based on conditions.
if(field == 'it_infra'){
var cat_id = g_form.getValue('sysparm_item_guid');
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sn_hr_core_case"); //Update your table
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
g_form.addErrorMessage('You must add an attachment before submitting this request.');
return false;
}
}
}
When I click on submit it always throwing the below warning message:
(GlideRecord) [Q:NOCB] Query must be called with a callback function.
The form is not submitting on the valid case also. How to fix this issue.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2020 06:17 AM
Greetings Abdul,
The error relates to your gr.query() line - in that all gliderecord calls from the client side require a responseFunction per - https://developer.servicenow.com/dev.do#!/reference/api/orlando/client/c_GlideRecordClientSideAPI#r_...
But, before you go and adjust that - you should instead, create a script include and use the GlideAjax API, or use the REST APIs
-AJB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2020 07:01 AM
Did you accidentally mark other response as correct?
Would you mind marking my response as correct and helpful If I was able to help you?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2020 06:17 AM
Greetings Abdul,
The error relates to your gr.query() line - in that all gliderecord calls from the client side require a responseFunction per - https://developer.servicenow.com/dev.do#!/reference/api/orlando/client/c_GlideRecordClientSideAPI#r_...
But, before you go and adjust that - you should instead, create a script include and use the GlideAjax API, or use the REST APIs
-AJB

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2020 06:58 AM
Thanks for the reference

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2020 06:56 AM
Hi team, I can able to resolve my issue with the following logic:
function onSubmit() {
//Get the field
var field= g_form.getValue("hr_process");
//Make attachment mandatory only based on conditions.
if(field == 'it_infra'){
var cat_id = top.window.$("#sc_cat_item").scope().$parent.attachments;
var length = cat_id.length;
if(length <= 0) {
g_form.addErrorMessage('You must add an attachment before submitting this request.');
return false;
}
}
}