function searchRecord(recordType, savedSearch, arrFilters, arrColumns, filterExpression) { try { var search = null; // if a saved search is provided, load it and add the filters and // columns if (isNotEmpty(savedSearch)) { search = nlapiLoadSearch(recordType, savedSearch); if (isArrayNotEmpty(arrFilters)) { search.addFilters(arrFilters); } if (isArrayNotEmpty(arrColumns)) { search.addColumns(arrColumns); } if (isArrayNotEmpty(filterExpression)) { search.setFilterExpression(filterExpression); } } // create a new search else { search = nlapiCreateSearch(recordType, arrFilters, arrColumns); } // run search var resultSet = search.runSearch(); // iterate through the search and get all data 1000 at a time var searchResultCount = 0; var resultSlice = null; var searchResult = []; do { resultSlice = resultSet.getResults(searchResultCount, searchResultCount + 1000); if (resultSlice) { resultSlice.forEach(function(result) { searchResult.push(result); searchResultCount++; }); } } while (isArrayNotEmpty(resultSlice) && resultSlice.length >= 1000); return searchResult; } catch (err) { nlapiLogExecution('ERROR', 'searchRecord', err); throw err; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter