Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @NApiVersion 2.1
- * @NScriptType Restlet
- * @NmoduleScope Public
- */
- define(['N/search'],
- function (search) {
- /**
- * Function called upon sending a GET request to the RESTlet.
- *
- * @param {Object} requestParams - Parameters from HTTP request URL; parameters will be passed into function as an Object (for all supported content types)
- * @returns {string | Object} HTTP response body; return string when request Content-Type is 'text/plain'; return Object when request Content-Type is 'application/json'
- * @since 2015.1
- */
- function doPost(requestParams) {
- let results = [];
- let slice = [];
- let i = 0;
- let startDate = requestParams.startDate;
- var endDate = requestParams.endDate;
- var kitchenSubsidiaries = [10, 37, 56];
- var kitchenLocations = [3, 5, 7];
- var brainSearch = search.create({
- type: search.Type.SALES_ORDER, // change to the ID of your saved search
- //id: 'customsearch1166',
- title: 'Kitchen Brain Integration',
- columns: ['internalId', 'entity', 'subsidiary', 'item', 'units', 'custbody_document_date'],
- filters: [
- ['status', search.Operator.NONEOF, ["Cancelled", "Closed", "FullyBilled", "PendingApproval"]],
- ['custbody_document_date', search.Operator.WITHIN, [startDate, endDate]],
- ['subsidiary', search.Operator.ANYOF, kitchenSubsidiaries],
- ['location', search.Operator.ANYOF, kitchenLocations]
- ]
- });
- var resultSet = brainSearch.run();
- do {
- slice = resultSet.getRange({start: i, end: i + 999});
- slice.forEach(function (row) {
- var resultObj = {};
- row.columns.forEach(function (column) {
- resultObj[column.name] = row.getValue(column);
- });
- results.push(resultObj);
- i++;
- });
- } while (slice.length >= 1000);
- return JSON.stringify(results);
- }
- return {
- post: doPost
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement