- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:05 PM
How does data flow between the server script and the client controller in a widget? What’s the best way to handle asynchronous updates?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:10 PM
When the widget loads, the server script executes first on the ServiceNow server. The data object returned from the server script is sent to the client controller (AngularJS). This data object becomes available as c.data inside the client controller.
If you need to refresh or update data after the initial load (without reloading the whole widget), use spUtil.get or $http.post to call the server script again asynchronously.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:23 PM
// Server Script
(function() {
data.user = gs.getUserDisplayName();
data.incidents = [];
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', gs.getUserID());
gr.query();
while (gr.next()) {
data.incidents.push({
number: gr.number.toString(),
short_description: gr.short_description.toString()
});
}
})();
js
Copy code
// Client Controller
function($scope) {
var c = this;
console.log(c.data.user); // Accesses value from server
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:10 PM
When the widget loads, the server script executes first on the ServiceNow server. The data object returned from the server script is sent to the client controller (AngularJS). This data object becomes available as c.data inside the client controller.
If you need to refresh or update data after the initial load (without reloading the whole widget), use spUtil.get or $http.post to call the server script again asynchronously.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:10 PM
Let me know if you need any Sample Code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:12 PM
Yes Please that will be of great help !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2025 11:23 PM
// Server Script
(function() {
data.user = gs.getUserDisplayName();
data.incidents = [];
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', gs.getUserID());
gr.query();
while (gr.next()) {
data.incidents.push({
number: gr.number.toString(),
short_description: gr.short_description.toString()
});
}
})();
js
Copy code
// Client Controller
function($scope) {
var c = this;
console.log(c.data.user); // Accesses value from server
}