Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Returning all ltems from a list #44

Open
DavidPratten opened this issue Dec 24, 2018 · 1 comment
Open

Returning all ltems from a list #44

DavidPratten opened this issue Dec 24, 2018 · 1 comment
Assignees

Comments

@DavidPratten
Copy link

DavidPratten commented Dec 24, 2018

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
Copy link
Owner

Hi @DavidPratten

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.

@gitbrent gitbrent self-assigned this Dec 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants