I'm running a search that shows a number of groupe...
# suitescript
a
I'm running a search that shows a number of grouped results in the UI (1431), then when I do: • const nResultsCount = oSearch.runPaged({ pageSize: 1000 }).count; I also get the same amount of results: 1431. However I'm unable to get all the results when I loop through them and store them in an object, I only get 1362 results. Any ideas?
e
You'll need to share your loop I think
a
This is how my columns look like:
Copy code
const oColumnsMap = {
    CUSTOMER: {name: 'entity', summary: search.Summary.GROUP},
    CUSTOM_FIELD: {name: 'custbody_cust_field', summary: search.Summary.GROUP},
    DATE: {name: 'trandate', summary: search.Summary.MIN}
};
This is how I get my results...
e
My guess is you have key collisions when storing in the object. Doesn't seem like a loop bounds issue. Or if this isn't running as Admin, then potentially permissions
s
it might be a long shot, but you might try changing how the search results are sorted in the search definition.
a
Untitled.js
Since the columns are grouped by ENTITY and CUSTOM FIELD, the results are UNIQUE and I'm using that as a KEY, on line 15 of the snippet above ^^^. Still my results count is 1431 and my
oResultsData
ends with 1362 keys.
Both searches in the UI and the code are using the same columns and filters.
c
I second Eric's suggestion that it might be permission/restriction related
a
It is a Suitelet and it is running as Administrator
šŸ‘ 1
c
I read too quickly and originally missed where you said
nResultsCount
=== 1431. What I would do to untangle is ensure that the inner loop is actually being executed 1431 times, and also to rule out key collisions. I'd create a separate array to push the raw results onto and check its count, also process to 100% confirm unique keys. My eye is on the values of keys being overwritten on line 15.
ā˜ļø 1
a
@Clay Roper Did that, there is some key collision as you and @erictgrubaugh are thinking, but the problem is it does not make sense...
Untitled.js
e
Why not? What makes Entity+CustomField unique?
a
Grouping ^^^
c
Per @shea brennan’s suggestion above, are you explicitly sorting? I don't used paged searches enough to know them well, but I have run into issues at page boundaries on paged queries without explicit sorting.
ā˜ļø 1
b
make an array of results instead
then log its length
after that, revisit the first thing eric told you
a
@battk I did that, is working, I got the 1431 results I see in the UI in the array of results. So what @erictgrubaugh said is true, there is keys collisions, the big question is WHY?
c
@alien4u When you have multiple rows with the same synthesized key, does the date value differ?
b
it should not be hard to add a guard to your code to figure out where the collision is
a
No, is unique, one example grouped result in the UI: • CUSTOMER: CUSTOMER_ABC • CUSTOM_FIELD: 80-LOT • DATE: 05/31/2024 That combination is unique in the UI, however I'm unable to get that result (when doing
${oData.CUSTOMER}||${oData.CUSTOM_FIELD}
) in the script.
r
When you are creating the key you can just check if it already exist in your object Then print the existing key in your object vs the key from the current loop you created and see what's different on those 2 data sets
e
Is your custom field a list?
a
Yes
e
Cust 123 + List 4
a
List/Record - Custom Record
e
use getText
a
I got 69 assumed collisions, the deal is that the result I'm looking for is not one of those collisions, this gets weird by the minute...
Added this to my loop
s
you aren't getting all the results. you're getting duplicates. try applying a sort in the search definition used in the script by some field in the result set.
a
Untitled.js
None of the supposed collisions found is a result I can see in the UI but unable to get into my results object.
@shea brennan That solved the issue... Long history short, you must sort by one of your grouping columns if you want grouping to work properly.
CRAZY
s
result ordering in paginated searches isn't guaranteed
unless the results are ordered by a field in the result set.
it's wild
e
(Sorry, didn't see the separator in your key.)
šŸ‘ 1
a
Thank you all for your help...
šŸ™Œ 2
s
We saw this duplicates behavior as well with
runPaged()
and basically just switched to using
getRange()
and it avoided the problem.