How to pass data to server in widget on click of tabs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2016 12:16 AM
Hi- I am configuring data table widget and I have created two tabs like My tickets, My assigned tickets on HTML. When user click on those tabs I have pass tab value and specific data to server so that it can return value based on tab click.
Has anyone implemented such thing in service portal. It would be great if any direction would be provided.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2016 08:15 AM
I would take a look at spUtil.refresh() and server.refresh()
documentation/widget_client_script_apis.md at master · service-portal/documentation · GitHub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2016 02:06 AM
Hi Brad,
I have seen that page but I am not getting how to use the server.refresh and how can I pass "updated scope data to server" ? Could you please explain with some example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2016 07:42 PM
Did you figure out how to do this (without ServiceNow's approach to coding i.e Hardcoding)?
Also the "server.get" method is best to retrieve data from the server for this type of situation I believe but haven't even figured out how to dynamically add these requests to the tab elements and how it then returns the data and updates the data in the view. I'll let you know how I get on in the next few days and if I figure it out, I'll let you know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2016 05:07 PM
Update: It has to be hardcoded as I could not figure out a simple approach programmatically to solve this. Looking at the example in the SP for knowledge articles ServiceNow has also hardcoded it. The solution is to set URL of the tab to be the same page and pass a GET variable within the URI and test for that within the model.
View.
<a href="...?id=[sp_page]&tab=one">
<a href="...?id=[sp_page]&tab=two">
However, I have a display count in the tab and because this is $broadcast to the tab from the model that queries the DB (separate to the tab widget) for the records it does not update the count because the watcher does not rerun the controller. Which is very annoying because I now have to create an aggregate query for each count, thus adding performance issues (2 tabs = 4 queries) to a mobile platform.
Because isn't angular meant to be intelligent enough to update the data through the $broadcast events when the model and data is run/changes (maybe I'm using it wrong?), or have ServiceNow nurfed the basic fundamentals of angular?
Tabs Controller
$scope.$on("tab.counts", function($event, tab, value){
$scope.data.view[tab] = value;
});
Record/Data Controller
$rootScope.$broadcast("tab.counts", "open", data.count);
spUtil.recordWatch($scope, "table_name", "filter", function(name, data){
spUtil.refresh($scope);
});
I've even tried to add it directly to the watcher, even that doesn't work.
Record/Data Controller
$rootScope.$broadcast("tab.counts", "open", data.count);
spUtil.recordWatch($scope, "table_name", "filter", function(name, data){
spUtil.refresh($scope);
// doesn't work???
$rootScope.$broadcast("tab.counts", "open", data.count);
});