The CreatorCon Call for Content is officially open! Get started here.

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

hi Trevor,



one more attempt:


Is it possible to write to a dot-walked field on a form?



But newer post said dot walking are not able to be updated...


Dot walking in "Set field values" not working as expected in the Business rule


Unfortunately, those discussions refer to updating reference fields, which is not what I'm concerned about here. I am not performing any dot-walk operations to referenced tables.  


Bryan Tay3
Mega Guru

hi Trevor,



May I know what field "ref_incident" a custom added field/column?


I could not find it OOTB task/incident table.


I think SNOW store this field as a sys_id reference which allow dot walking but may not be able to directly updating it.




just like example below:


var incidentSysId = 'd2a8660d4f7bfa00fd793d501310c7a9';  


var taskGr = new GlideRecord('task');  


taskGr.get(incidentSysId);


gs.print(taskGr.u_requestor.first_name);


taskGr.u_requestor.first_name = "new_name";


taskGr.update(); //not working since the update are not for reference field sys_user.



I think u can also try this:



var incidentSysId = '0bd390a4138b8700834fbda12244b056';  


var taskGr = new GlideRecord('task');  


taskGr.get(incidentSysId);  


 


gs.print(taskGr.ref_incident.close_code);  


 


var taskGr2 = new GlideRecord('task');  


taskGr2.get(taskGr.ref_incident);  


taskGr2.close_code = 'Solved (Work Around)';  


taskGr2.update();  



Hope this helps.


Hello Bryan,



I use ref_incident.close_code because the "close code" field is not on the Task table. It is on an extended table, Incident. taskGr.close_code returns "undefined" while taskGr.ref_incident.close_code returns the close code value for an incident.


Jace Benson
Mega Sage

Here's how I'd do it if you cant ensure the table is always the same;



var sysId = "0bd390a4138b8700834fbda12244b056";


var taskGR = new GlideRecord("task");


if(taskGR.get(sysId)){


  //get classname


  var className = taskGR.getValue('sys_class_name');


  //you may want to only do this for incident


  var specificGR = new GlideRecord(className);


  if(specificGR.get(taskGR.getValue('sys_id'))){


      //if you want to leave it open, cehck if close code is valid


      if(specificGR.isValidField('close_code')){


          specificGR.setValue('close_code','Solved (Work Around)');


          specificGR.update();


      }


  }


}