How to add pagination on a custom widget for incident table ?What are service now best pratice method?

arun124
Kilo Contributor

HTML

<div>
<!-- your widget template -->
<pre>Sort by = {{orderField}}</pre>
<div><label>Search</label><input type="text" ng-model="searchText"/>
</div> <table>
<tr>
<th><button ng-click="changeSort('number')">Number</button></th>

<th><button ng-click="changeSort('short_description')">Short Description</button></th>

<th><button ng-click="changeSort('sys_updated_on')">Updated</button></th>
</tr>
<tr ng-repeat="incidentme in data.incidentsqw | orderBy:orderField | filter:searchText ">

<td>{{incidentme.number}}
</td>
<td> {{incidentme.short_description}}
</td>
<td> {{incidentme.sys_updated_on}}
</td>
</tr>
</table>
</div>

Client code

function($scope, spUtil) {
// widget controller
var c = this;
$scope.orderField = "number";
$scope.changeSort = function(field){
$scope.orderField = field;
}
spUtil.recordWatch($scope, "incident", "",function(name, data){
spUtil.update($scope);
});

}

 

 

server side code

 

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.incidentsqw = [];
var gr = new GlideRecord('incident');
gr.addActiveQuery();
//gr.setLimit(10);
gr.orderByDesc('sys_updated_on');
gr.query();
while(gr.next())
{
var incidentme = {};
incidentme.number=gr.getDisplayValue('number');
incidentme.short_description = gr.getDisplayValue('short_description');
incidentme.sys_id =gr.getUniqueValue();
incidentme.sys_updated_on=gr.getValue('sys_updated_on');
data.incidentsqw.push(incidentme);
}

})();

2 REPLIES 2

Barrilito van D
Kilo Guru

Hi Arun,

Just look in all the default out of the box widgets to learn how it works and what is there. There are list widgets and widgets to show listings of articles which are paginated, so look into there, learn, copy paste...  Then you are also in line with the ServiceNow way of working...

Good luck!

Barrilito van D
Kilo Guru

... and looking further on the community, see here for doing so on the simple list widget...

https://community.servicenow.com/community?id=community_question&sys_id=cb104f21db98dbc01dcaf3231f961921