
- 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 06:17 AM
Hi,
Using GlideRecord is not recommended in client script
try this
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(checkRecord);
function checkRecord(gr){
if(!gr.next()) {
g_form.addErrorMessage('You must add an attachment before submitting this request.');
return false;
}
}
}
}
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:18 AM
As you can see in Ankur's example, the query method requires a response function as a parameter. Per https://developer.servicenow.com/dev.do#!/reference/api/orlando/client/c_GlideRecordClientSideAPI#r_...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2020 06:20 AM
Try this without using GlideRecord as using GlideRecord is not recommended.
function onSubmit() {
//Get the field
var field = g_form.getValue("hr_process");
var count = getCurrentAttachmentNumber();
//Make attachment mandatory only based on conditions.
if(field == 'it_infra' && count == ''){
g_form.addErrorMessage('You must add an attachment before submitting this request.');
return false;
}
}
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:58 AM
Thanks for the comment