- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 10:16 AM
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?
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 11:14 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 10:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 10:23 AM
I've seen that, it's a different issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 10:38 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 11:14 AM
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.
