- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2022 08:07 AM
Hi,
I am creating a chart.js widget and it is getting its data from servicenow table using REST api. I want that when data changes in table and I save it. It should automatically be shown on widget without loading the page. Any suggestions?
CLIENT SCRIPT
api.controller=function($scope) {
/* widget controller */
var c = this;
$scope.labels = c.data.labels;
$scope.data = c.data.datas;
};
SERVER SCRIPT:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.labels = [];
data.datas = [];
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://dev60543.service-now.com/api/now/table/u_story_2_dashboard?sysparm_fields=u_data&sysparm_lim...');
request.setHttpMethod('GET');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'Qmyl91I!K/Ib';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
var response = request.execute();
var res =JSON.parse(response.getBody());
//var ar = JSON.parse(res)
//.u_data;
var result = res.result;
for(var i = 0; i<result.length;i++){
data.labels.push((JSON.parse(result[i].u_data).label).toString());
data.datas.push(JSON.parse(result[i].u_data).data);
}
})();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2022 03:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2022 03:21 AM
solved
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2023 02:30 AM
Can you write up how did you achieve it?
ServiceNow Consultant
United Kingdom