ServicePortal custom widget(scoped) - client script logs [object Object]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2018 02:26 PM
I am in the process of learning widget scripting.I want to display a record's 'Group' name from the server script on to widget HTML template on page loading. There is no 'input' for server script. The server script works fine and has the 'data.group_name' logged correctly. But the client script logs it as '[object Object]'. The preview displays an empty JSON {} on the page instead of Group name.What am I doing wrong?
HTML Template:
<div class="panel panel-default">
<!-- your widget template -->
<div class="panel-body">
<p >
Division of Information Technology - {{ c.data.group_name }}
</p>
</div>
</div>
Client Script:
function() {
/* widget controller */
var c = this;
console.log("c.data.group_name: " + c.data.group_name); //Logs as c.data.group_name: [object Object]
}
Server script:
(function() {
/* populate the 'data' object */
var potEventGR = new GlideRecord('x_15865_potluck_group_potluck_event');
var got = potEventGR.get('5c8a3fae4f421300bae4e321a310c716');
console.log('got' + ": " + got);// Logs as expected 'true'
data.group_name = potEventGR.event_group.name;
console.log('Server data.group_name' + ": " + data.group_name);// Logs as expected
})();
Any help is appreciated.....

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2018 02:32 PM
try console.log("c.data.group_name: " + c.data.group_name.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2018 02:53 PM
Thanks for the quick reply.That did not help. Still logging as [object Object] in Chrome

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2018 02:32 PM
You need to use getters and setters. Replace the following line;
data.group_name = potEventGR.event_group.name;
//with
data.group_name = potEventGR.getValue('event_group.name');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2018 02:54 PM
Tried but data.group_name logs as 'null'. The 'event_group' of record is a reference field (ServiceNow Group).