Service Portal Widget Update/Refresh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2019 08:35 AM
Hi community!
I am lacking basic understanding of Widget Development and therefore facing some issues here. Any advice would be highly appreciated. Even if it does not answer question directly, but gives so good practice advices.
Scenario: I am creating a dashboard using data-table widgets. The dashboard will display Tasks (in my case it will be a different table derived from Task, so let's just say Task for simplicity) for specified locations. There will be 3 tabs: Active Tasks, Closed Tasks, All Tasks under separate tabs. I declare them in Server Script:
At this point everything works just fine. As can be seen in the screenshot above, I am passing an array of location sys_ids (data.locationsToDisplay) as widget inputs.
Problem: I need to add a drop-down list of these locations (ones in data.locationsToDisplay) and allow a user to select a single location, so widgets can show Tasks associated with that location only, rather then Tasks for all the locations in data.locationsToDisplay. I created a dropdown and I can read a value of location (sys_id). My question is, how do I refresh my widgets? I tried c.server.refresh(), spUtil.refresh() and update() and had no success. I would really appreciate any advice or pseudocode workflow explanation (i.e.: get your sys id -> call [this method] -> ...)
Additional: I am retrieving the selected location value in Client Script. To simplify, I can hardcode it, say like this:
How can I now make widgets refresh for this location only? So far I don't quite understand the difference between $scope, this, c and scope in linked function, which confuses me even more.
Thanks everyone visiting this post!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2019 08:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2019 09:19 AM
Thank you, checking it out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2019 09:48 AM
You can try to use to execute $scope.$apply() with scope of destination widget or on the parent widget. See the article from official ServiceNow documentation about the usage of $apply().
Alternatively you can consider to implement event communication between your widgets. The child widget can wait for "refresh" event (using $on) and the parent widget can sent $emit with new location ids to child widgets.