In a Suitelet, the search I'm running to get a list of salesorders for a particular Customer ID returns lots of duplicates.
This is the code I'm using in the SuiteScript:
var curCustomerID = "123456"; // this number comes for elsewhere
var filters[0] = new nlobjSearchFilter('entity', null, 'is', curCustomerID);
var columns[0] = new nlobjSearchColumn('internalid');
var searchResults = ""; searchResults = nlapiSearchRecord('salesorder', null, filters, columns);
With the above, I get a list of salesorders internal IDs, which is exactly what I want.
The list will contain mostly duplicates. I don't see a pattern to why their are so many duplicate internal IDs. Some IDs are duplicated up to 15 times, some only 6, etc.
For most instances it's "OK" as I can sort through the list and remove duplicates. However, so some rare instances, the customer is so good over so many years (wholesale purchasers) that the list quickly hits the 1000 limit.
I would be "OK" with that as I'm only after the last 20 sales orders but the list is in ascending order so the 1000th result could be an order from 3 years ago.
What am I doing incorrectly in my search that would have the results be duplicated so much?
What can I change to not have duplicates?
If I have to have duplicates, what can I do to have the list in descending order?
Thanks
Sam W.
PS -
Here is a sample of the results that I've listed out within a loop so I could see what was going on.
Salesorder with internal ID of 11079 has 14 items in it, 10830 has three items.
searchResults.length 1000
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 110079
-- ids[i]: 108030
-- ids[i]: 108030
-- ids[i]: 108030
-- ids[i]: 108030
-- ids[i]: 108030
-- ids[i]: 108030
-- ids[i]: 108029
-- ids[i]: 108029
-- ids[i]: 108029