Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. /**
  2. * @NApiVersion 2.1
  3. * @NScriptType Restlet
  4. * @NmoduleScope Public
  5. */
  6. define(['N/search'],
  7. function (search) {
  8.  
  9. /**
  10. * Function called upon sending a GET request to the RESTlet.
  11. *
  12. * @param {Object} requestParams - Parameters from HTTP request URL; parameters will be passed into function as an Object (for all supported content types)
  13. * @returns {string | Object} HTTP response body; return string when request Content-Type is 'text/plain'; return Object when request Content-Type is 'application/json'
  14. * @since 2015.1
  15. */
  16. function doPost(requestParams) {
  17.  
  18. let results = [];
  19. let slice = [];
  20. let i = 0;
  21. let startDate = requestParams.startDate;
  22. var endDate = requestParams.endDate;
  23. var kitchenSubsidiaries = [10, 37, 56];
  24. var kitchenLocations = [3, 5, 7];
  25.  
  26. var brainSearch = search.create({
  27. type: search.Type.SALES_ORDER, // change to the ID of your saved search
  28. //id: 'customsearch1166',
  29. title: 'Kitchen Brain Integration',
  30. columns: ['internalId', 'entity', 'subsidiary', 'item', 'units', 'custbody_document_date'],
  31. filters: [
  32. ['status', search.Operator.NONEOF, ["Cancelled", "Closed", "FullyBilled", "PendingApproval"]],
  33. ['custbody_document_date', search.Operator.WITHIN, [startDate, endDate]],
  34. ['subsidiary', search.Operator.ANYOF, kitchenSubsidiaries],
  35. ['location', search.Operator.ANYOF, kitchenLocations]
  36. ]
  37. });
  38.  
  39. var resultSet = brainSearch.run();
  40.  
  41. do {
  42. slice = resultSet.getRange({start: i, end: i + 999});
  43. slice.forEach(function (row) {
  44. var resultObj = {};
  45. row.columns.forEach(function (column) {
  46. resultObj[column.name] = row.getValue(column);
  47. });
  48. results.push(resultObj);
  49. i++;
  50. });
  51. } while (slice.length >= 1000);
  52.  
  53. return JSON.stringify(results);
  54. }
  55.  
  56. return {
  57. post: doPost
  58. };
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement