Returning all ltems from a list
DavidPratten opened this issue · 1 comments
DavidPratten commented
The methods available for returning list items are paged. Can the pattern below be made more general or idiomatic?
The desired function
getRecords('Test',['ID', 'Title', 'SupplierId'])
.then(function(ret) {
console.log(ret);
});
returns
{list: 'Test', listCols: ['ID', 'Title', 'SupplierId'], data: [{},...]}
implementation
function getRecords(list, listCols) {
return new Promise(function(resolve) {
var data = [];
function innerGetRecords(dataPage) {
if (dataPage) {
data = data.concat(dataPage);
if ('__next' in dataPage[0]) {
sprLib.list(list)
.items({
listCols: listCols,
queryNext: dataPage[0].__next
})
.then(innerGetRecords)
.catch(errMsg => console.error(errMsg));
} else {
resolve({list: list,listCols: listCols,data: data})
}
} else {
sprLib.list(list)
.items({
listCols: listCols,
queryLimit: 5000 // library's upper limit
})
.then(innerGetRecords)
.catch(errMsg => console.error(errMsg));
};
}
innerGetRecords();
});
}
gitbrent commented
Thanks for the suggestion. Many users undoubtedly deal with larger datasets, so it's a feature i'd like to implement.
I'm imagining a new flag to existing methods, like items()
that would denote the desire to receive all the items.
sprLib.list('Accounts').items({
listCols: ['ID', 'Title']
getAllItems: true
});
I'll post an update when this feature lands so you can give it a spin.