- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 11-07-2018 11:47 AM
I received a call asking for assistance paginating through a GlideRecord result-set in a Scoped Application. I was informed that GlideRecord.currentLocation doesn't work in scoped apps, and solutions here at community are overly complicated that use legacy JavaScript (by that I understood prototypejs).
So here is code to paginate through a result set. There is not much to it except the use of GlideRecord.chooseWindow (a function that allows records to be retrieved at specific places). It has no checks and balances, so if you need those, add them. With the addition of chooseWindow, GlideRecord acts as if 'paging'
var Paginator = {
paginate: function (table) {
//initializer section
var glide = new GlideRecord(table);
return function getNext(start, end) {
glide.chooseWindow(start, end);
glide.query();
gs.debug(start + " " + end);
while (glide.next()) {
gs.debug(glide.getDisplayValue() + ' ' + glide.short_description);
}
}
}
};
Use it
var starts = [0, 10, 20, 30];
var getNext = Paginator.paginate('incident');
var PAGE_SIZE = 9;
for (var x = 0; x < starts.length; x++ ) {
getNext(starts[x], starts[x] + PAGE_SIZE);
}
Or
Paginator.paginate('incident')(50, 120);
Strategy:
Remove all the overhead possible by
- Use a closure not to have to pass around a copy of a function increasing the size of the stack
- The closure prevents further performance hits caused by the new GlideRecord each time a call is made to fetch more records
- Return a function from the initial function
- "Functionalize" function paginate a little bit
- Get rid of another call to new when using Prototype.js Class.create
Result:
*** Script: [DEBUG] 0 9
*** Script: [DEBUG] INC17-0000019 Token Locked
*** Script: [DEBUG] INC17-0000022 Outlook issues
*** Script: [DEBUG] INC17-0000023 Outlook Issue
*** Script: [DEBUG] INC17-0000024 Apple Watch Question
*** Script: [DEBUG] INC17-0000025 Cannot connect to any WiFi networks
*** Script: [DEBUG] INC17-0000026 Cannot edit Boardvantage document
*** Script: [DEBUG] INC17-0000029 Service Now Incidents
*** Script: [DEBUG] INC17-0000031 Service now
*** Script: [DEBUG] INC17-0000032 Add-ins don't stay enabled
*** Script: [DEBUG] 10 19
*** Script: [DEBUG] INC17-0000034 Remote access issue
*** Script: [DEBUG] INC17-0000035 VPN login failed
*** Script: [DEBUG] INC17-0000039 Outlook Issue
*** Script: [DEBUG] INC17-0000040 Token Issue
*** Script: [DEBUG] INC17-0000041 Blackberry Classic Connection Issue
*** Script: [DEBUG] INC17-0000042 Forgot Passcode
*** Script: [DEBUG] INC17-0000043 Token Issue
*** Script: [DEBUG] INC17-0000044 Token Locked
*** Script: [DEBUG] INC17-0000045 Inbox Empty
*** Script: [DEBUG] 20 29
*** Script: [DEBUG] INC17-0000047 Temporary Quarantine
*** Script: [DEBUG] INC17-0000048 Lazard emails after password change
*** Script: [DEBUG] INC17-0000049 Expired Password
*** Script: [DEBUG] INC17-0000050 Temporary Quarantine
*** Script: [DEBUG] INC17-0000051 Unable to load sharepoint site
*** Script: [DEBUG] INC17-0000052 Outlook trying to connect
*** Script: [DEBUG] INC17-0000053 Shared drives not mapping on vpn
*** Script: [DEBUG] INC17-0000054 Factset Addon in ribbon
*** Script: [DEBUG] INC17-0000055 FactSet Error message
*** Script: [DEBUG] 30 39
*** Script: [DEBUG] INC17-0000059 Cap IQ add in issue
*** Script: [DEBUG] INC17-0000060 Locked account
*** Script: [DEBUG] INC17-0000061 Unable to access notes
*** Script: [DEBUG] INC17-0000062 drives not showing
*** Script: [DEBUG] INC17-0000063 unable to login to Lotus Notes
*** Script: [DEBUG] INC17-0000064 account is locked
*** Script: [DEBUG] INC17-0000066 VPN: login failed
*** Script: [DEBUG] INC17-0000068 RSA account check
*** Script: [DEBUG] INC17-0000069 Remote login - Cisco any connect not working
- 1,833 Views