Widget: parse response from c.server.get
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 10:14 AM
c.parameters = {sys_id: sys_id, action: "getCustomerBySysId"};
c.server.get(c.parameters).then(function(response) {
console.log("customer", response.data.customer);
console.log("name", response.data.customer.name);
console.log("status", response.data.customer.status);
});
This is the Client Script. Each console.log says that this is an object, but they are just Strings in the DB.
This is the Server Script:
var y = new GlideRecord('x_11111_customers');
y.addQuery('sys_id',input.sys_id);
y.query();
while(y.next())
{
data.customer = y;
}
}
How can I get name and status of a Customer in Client Script side ?
And how also can I get a Reference field (e.g. customer has "Manager" field which is Reference). How in this case I can get "name" from manager field ?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 10:37 AM
In client controller you can use $scope.data.customer. Below is the sample client controller.
function($scope) {
/* widget controller */
var c = this;
var aa= $scope.data.customer;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 02:27 AM
It doesn't work. It returns undefined.
I need it by response from c.server.get

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 02:41 AM
Could you please share your client and server side code of the widget.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 03:02 AM
Sure:
Client Script:
function($scope, spUtil) {
/* widget controller */
var c = this;
c.server.get({
action: "getCustomerBySysId",
sys_id: sys_id
}).then(function(response) {
console.log("customer", response.data.customer);
console.log("name", response.data.customer.name);
console.log("status", response.data.customer.status);
});
}
Server Script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
if (input){
if (input.action == 'getCustomerBySysId'){
var y = new GlideRecord('x_11111_customers');
y.addQuery('sys_id',input.sys_id);
y.query();
while(y.next()) {
data.customer = {
name: y.name,
status: y.status
};
}
}
}
})();