getRefRecord() returns an empty record

kirkr
Tera Expert

I am creating a custom widget that pulls data from a table and I'm running in to odd behavior with getRefRecord()

On the table is a reference field u_operational_owner which is a reference to sys_user.

If I pull the field in like this, it works. The variable gr is a GlideRecord

data.operational_owner = gr.getDisplayValue('u_operational_owner');

If I change it like this, I get {}

var opOwner = gr.u_operational_owner.getRefRecord();

data.operational_owner = opOwner.name;

If I inspect opOwner, it appears to be an empty sys_user record.

Any ideas on this one?

1 ACCEPTED SOLUTION

It turned out that I needed to add toString() to the field. It seems the Server Script for a Widget works slightly different. Everything worked fine as a Background Script, but it was strange in the widget.



var opOwner = gr.u_operational_owner.getRefRecord();


data.operational_owner = opOwner.name.toString();



When I dumped the opOwner to to the console, it appeared as an empty sys_user. Very odd, but glad it's working now. Thank you for helping.


View solution in original post

4 REPLIES 4

Chandu Telu
Tera Guru

I've seen that, it's a different issue.


HI Kirkr,



i tested the below code it's working fine



var gr = new GlideRecord('incident');


gr.get('2219abb8db9583003b70f00fbf961902');


var caller = gr.caller_id.getRefRecord(); //Gets the sys_user GlideRecord for the caller


gs.log(caller.name)



it will returning the user name



1) Are you using   the scoped application


It turned out that I needed to add toString() to the field. It seems the Server Script for a Widget works slightly different. Everything worked fine as a Background Script, but it was strange in the widget.



var opOwner = gr.u_operational_owner.getRefRecord();


data.operational_owner = opOwner.name.toString();



When I dumped the opOwner to to the console, it appeared as an empty sys_user. Very odd, but glad it's working now. Thank you for helping.