OnSubmit Catalog client script to update custom field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â05-07-2021 04:34 AM
Hello,
I have a requirement to get the variable value & check in my custom table for matching record & then to update the state value to 'completed' in my custom table.
I am using a OnSubmit catalog client script but it is not updating my custom table field state.
Type:OnSubmit
Catalog Item: Source Form Details
Script:
function onSubmit() {
//Type appropriate comment here, and begin script below
var sId = g_form.getValue('source_id'); // variable value
var gr = new GlideRecord('u_customtable'); // custom table
gr.addQuery('u_source','=',sId); // checking source id is available in my custom table
gr.query();
if(gr.next()){
var sts = gr.u_state;
g_form.setValue(sts,'Completed'); // setting the value of my custom table to 'Completed' but not working.
gr.update();
}
else{
// do nothing
}
}
Is this a correct approch or iam missing something. Plz help.
Thx,
JR
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â05-07-2021 04:40 AM
Hi,
You cannot use GlideRecord Query for updating record in Client script.
Instead use a GlideAjax call make a call to function and perform update operation in script include.
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â05-07-2021 04:42 AM
Hi,
This is not the right approach to do that. You can not do the server query from the client without calling a script include.
You have to call a script include by using a GlideAjax, The returned value from the Script include should set to the field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â05-07-2021 04:44 AM
Please find below link to learn how to use glide ajax:
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â05-07-2021 05:08 AM
Better approach is to use workflow run script since you must be having already workflow for your catalog item
Use this in workflow run script
var sId = current.variables.source_id;
var gr = new GlideRecord('u_customtable'); // custom table
gr.addQuery('u_source', sId); // checking source id is available in my custom table
gr.query();
if(gr.next()){
gr.setValue('u_state','Completed'); // setting the value of my custom table to 'Completed' but not working.
gr.update();
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader