Forum Discussion

Begbie's avatar
Begbie
Helper I
3 years ago

List.Generate and pagination

Hi All,

 

Wondering if someone can help at all, as I have been trying to do cursor based pagination using the List.Generate function and whilst I initially struggled, I have also realised why I kept getting an error doing it.

 

When the initial API call is made it returns 64,000 rows and a pagination token is created:

"pagination": {
        "next": "bd4b9e12"
    },

 

Give the token and it will then retrieve the next 34,000 rows of data, but the pagination token has now changed from "next" to "previous"

"pagination": {
        "previous": "eaf3358b"
    },

 

When you then try to do the 2nd condition in the List.Generate function, most how-to guides are looking for the value of null on the pagination.next value, but when it gets to the end, the data value doesn't exist as it has now changed to "previous", so the function now throws an error that the "next"field wasn't found

Expression.Error: The field 'next' of the record wasn't found.
Details:
    previous=ff215675

 

The condition being used in the List.Generate:

each [Result][pagination][next] <> null,

 

Any ideas on how to do the condition on this at all?

 

Thanks in advance ğŸ˜Š

4 Replies

  • ppm1's avatar
    ppm1
    Solution Sage

    How about using try ... otherwise

     

    each try [Result][pagination][next] otherwise null <> null,

     

    Pat

    • Begbie's avatar
      Begbie
      Helper I

      Thank you ppm1 seems a different error is now presented:

       

      Expression.Error: We cannot convert the value "ead5cb33" to type Logical.
      Details:
          Value=ead5cb33
          Type=[Type]

       

      Any ideas?

      • ppm1's avatar
        ppm1
        Solution Sage

        Hard to troubleshoot w/o being to connect myself, but please try this

         

        each (try [Result][pagination][next] otherwise null) <> null,

         

        Pat

  • Hi ppm1 

     

    Thanks again for trying to help troubleshoot this and can understand it is hard to work blind on this. I do hope the explainations I have given do help.

     

    I have tried the new query you gave above and this has now resulted in:

    As always, your help is greatly appreciated ğŸ˜Š

     

    Thanks