Does anyone know why this script might be duplicat...
# suitescript
y
Does anyone know why this script might be duplicating the same results out of a Saved Search when they aren't being duplicated when I go to view it (and filter the same exact records)? The number of records it returns is fine (i.e. if there's 1500 records in the SS, then there'll be 1500 items returned) however it goes ahead and duplicates some records. This is the script I'm using: /** * @NApiVersion 2.x * @NScriptType RESTlet */ define(['N/search'], function (search) { function loadAndRunSearch() { try { // Load your search into memory var mySearch = search.load({ id: 'customsearchBlah' }); // Run paged version of search with 1000 results per page var myPagedData = mySearch.runPaged({ pageSize: 1000 }); // Iterate over each page var results = []; myPagedData.pageRanges.forEach(function (pageRange) { // Fetch the results on the current page var myPage = myPagedData.fetch({ index: pageRange.index }); // Iterate over the list of results on the current page myPage.data.forEach(function (result) { // Process the individual result results.push(result); }); }); return JSON.stringify(results); } catch (err) { log.error('An error occurred', err); return { error: { code: 'ERROR_ON_GET', message: 'An error occurred trying to submit the saved search' } }; } } return { get: loadAndRunSearch }; }); I did notice that for smaller saved searches it seems to be fine and doesn't duplicate the records, so I tried upping the 1000 limit above thinking that may help, but it didn't really seem to do anything either...does anyone know why this could be happening? I only really notice it if there are more than approx. 900-1000 records in a saved search
r
Do you have a joined table without realizing it? such as address off of customer that maybe returning joined(multiplicative) results? I would add some logging to help troubleshoot as well. Can you preproduce with multiple calls in a row with same parameters? Is the data relatively static meaning if you run it off business or data change hours can you reporduce?
just some thoughts
y
@redfishdev do you mean a join that's within the saved search itself? I think we are joining on a few things, yet when I search/ filter on the same ID (e.g. 1234) in the saved search within Netsuite, I only see the record show up once, whereas filtering it in code (nodejs) it seems to appear twice. Is that what you are referring to though? Or do you mean somewhere possibly in the script shown above?
r
inside the saved search. I export items in restlet via Saved Searches regularly and whenever I see dups it is usually something inside the Search that is a joined table.
y
Cool, I'll try to take a look and see what I can find, thank you 🙂
r
you have to recreate the issue repeatably IMHO. You can always take the saved search amd rename and save as/ then add a group by cust id or what ever
and count of some field
then sort by the count
if you see 2 then you know it is the SS
then remove results items until you see no 2 count fileds
e
You're not returning `true`in your
myPage.data.forEach()
call.
y
@ehcanadian thanks! I'll give that a try and see how I go!
e
I've confused my searches,
data
there is an array so returning true won't make a difference, 😕
y
Yeahhh I just gave it a try and no luck on my end either 😞
I found it! I don't know why it's happening (but I'm going to ask my team, they're a lot more familiar with how saved searches work than I am), but in case anyone else here might know (and want the answer), when I click on the record in the saved search, it does actually open up two records, so while on the saved search I see the condensed list of items (i.e. just one record), if I click onto that record it then does open up two records before letting me select which one to actually go into. I'm not sure if this is because we were using (GROUP) in the criteria...but there you go 🙂
I can confirm it is to do with using "GROUP" as a summary type in the results, and because those records had multiple line items, per the number of line items is how many records I'd see broken down (when clicking on the record in the saved search UI) 🙂 thanks all!
r
its a hidden join
most likely
y
@redfishdev yeah I have a feeling too! Thanks for your advice above with that 🙂