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