OnSubmit Catalog client script to update custom field value

joshualazzarus
Mega Contributor

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

5 REPLIES 5

@joshualazzarus 

Thank you for marking my response as helpful.

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader