Refresh list widget data on click of refresh button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2023 06:43 AM
Hi,
1. I have created a list type custom widget which shows top 15 incidents created recently. It has a refresh button, once a user clicks on to it, the data should get refreshed(if any new incident is created that should come in the list).
2. how we can refresh the list if a new incident gets created at the backend(without clicking any button)
HTML
<div>
<div style="border: 1px solid black; width:163px;
height:30px; display:flex;
align-items: center;
background-color:grey; color:white;
padding:5px;">
Top 15 Incidents
</div>
<table border="1px solid black">
<tr ng-repeat="x in data.array">
<td style="height:30px; width:163px; padding:5px;">{{x.number}}</td>
</tr>
</table>
</div>
Server
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var gr = new GlideRecord('incident');
gr.orderByDesc('sys_created_on');
gr.setLimit(15);
gr.query();
data.array = [];
while(gr.next()){
var out = {};
out.number = gr.getValue('number');
data.array.push(out);
}
})();
- Labels:
-
Service Portal
-
widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2023 09:13 AM
The refresh button can look like this:
<button class="btn action-btn" ng-click="c.server.update()">Update</button>
However if you want to automatically update, you should take a look on record watchers (spUtil::recordWatch😞
function (spUtil, $scope) {
/* widget controller */
var c =this;
spUtil.recordWatch($scope, "incident", "active=true");
}
Before investing too much work into your custom widget, please also take a look at the out of the box Simple List widget.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2024 09:05 PM
Hello @AbhishekJain19
Use below client side controller code on your widget to show server updates with refresh rate of 2 seconds without clicking on any buttons.
var refresh = setInterval(timerun,2000) // for every 2 seconds
function timerun()
{
c.server.update();
}
If it was helpful, Kindly click on "Helpful" and mark it as "Accepted solution"