Setting Extended Field with GlideRecord

Trevor Muhl
Kilo Sage

Hello all,

I have found multiple discussions that describe how to get a field value from an extended table. However, none address how to set that same field value. Unfortunately, the following background script does not update the incident "close code" as I expect:

var incidentSysId = '0bd390a4138b8700834fbda12244b056';

var taskGr = new GlideRecord('task');

taskGr.get(incidentSysId);

gs.print(taskGr.ref_incident.close_code);

taskGr.ref_incident.close_code = 'Solved (Work Around)';

taskGr.update();

Is there any method to do so with a 'task' GlideRecord? Am I required to do this using an 'incident' GlideRecord? Thank you for your time.

- Trevor Muhl

10 REPLIES 10

Jace Benson
Mega Sage

IF you're in global scope you want to use the method, updateWithReferences();



https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_GlideRecord-updateWithReferences_Ob...


Hello Jace,



Thank you for your response. Unfortunately, I am trying to update a field on an extended table, not a field on a referenced table.


My mistake.   You'll have to GlideRecord to the proper class then.   You could do a quick get for the sys_class_name, then do another get to the proper class to set proper field for the extended table.


I was concerned this might be the case.