Does anyone know how I can restrict a restlet scri...
# suitescript
g
Does anyone know how I can restrict a restlet script that gets results from a saved search to a maximum of 500 unique records each time?
n
You could run the search paged with a page limit of 500 and then only return the first page
g
actually, the problem is as the results are at line level if a record is overlapping at 499,500 & 501 lines, ideally, it should give 501 or 498 hence was looking at getting unique records rather than limiting by page...
also out of interest, how would I limit by page and return only first page?
n
Ah i see. So do you want 500 unique transactions back? Or a max 500 results and the transaction lines have to fit within that 500.
and does it have to be a saved search? Or can you change it to use a query instead?
g
yeah 500 unique records for each execution, ideally based on a saved search...
n
Someone will hopefully jump in and provide a less messy solution here. But my thought is run the search, and get all results. Store the internal id's of the transaction for each line in a new Set() to get a list of unique id's. and when your set.length === 500 stop the search. Then run the search again, and push the results to a new array only if the transaction id is in your list of 500 internal id's
That kind of sucks because you have to run the search twice. But that's my initial thought
or using the paged method. Push a mainline = t filter to your saved search and run it paged with a limit of 500. Then same logic. Store the internal id's of the transactions in an array. Run the search again with mainline = false and compare each result with your list of transaction id's. And only return the ones that have a match
c
@G What criteria determine which 500 unique records to fetch? Are you storing any reference to what was fetched last time for some kind of pagination / making sure you don't duplicate with subsequent fetches?
☝️ 1
r
By 500 unique records you man 500 transactions or 500 lines ? And why limit to 500 records ? I have done something similar where first time restlet triggers and provides the total output count. And then with lower limit and upper limit, through multiple calls the data got fetched.
e
Edit the search to return the 500 records you want.