JM Acuesta
09/03/2021, 8:05 AMdefine(['N/runtime',
'N/search',
'N/record',
'N/task',
'N/file'
], function(runtime, search, record, task, file) {
function get(context) {
const searchResult = fetchSearchResults(filterData);
return JSON.stringify(searchResult);
}
const fetchSearchResults = (filterData) => {
const { savedSearchId, startDate: startDateTime, endDate: endDateTime, rows, force } = filterData;
let searchObj = {};
try {
searchObj = search.load({
id: savedSearchId
});
} catch (e) {
return {
error_code: 400,
details: `Saved Search ID not found: (${savedSearchId})`
};
}
const results = getResults(searchObj.run(), rows);
return results.map(mapSearchResults);
}
const getResults = (savedSearchObj, rows) => {
let holder = [];
const limit = 100000;
let i = 0;
while (true) {
if (holder.length == limit) break;
const result = savedSearchObj.getRange({
start: i,
end: i + 1000
});
if (!result) break;
holder = holder.concat(result);
if (result.length < 1000) break;
i += 1000;
log.emergency({
title: `get Results data ${i + 1}`,
details: {
notResult: !result,
resultLengthLessOneK: result.length < 1000,
i: i
}
});
}
};
const mapSearchResults = (result) => {
const columns = result.columns;
const obj = {};
columns.forEach((column, idx) => {
const textData = result.getText(columns[idx]);
const valueData = result.getValue(columns[idx]);
obj[column.label] = !!textData ? textData : valueData;
});
return obj;
};
return {
get
}
});
I always get
UNEXPECTED_ERROR | An unexpected SuiteScript error has occurred
when trying above 30k resultsbattk
09/03/2021, 8:54 AMbattk
09/03/2021, 8:54 AMbattk
09/03/2021, 9:06 AMbattk
09/03/2021, 9:07 AMstalbert
09/03/2021, 2:22 PMreturn Seq(LazySearch.load(searchid)).map(nsSearchResult2Obj()).toArray()