Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. exports.runPaged = function (searchDefinition) {
  2.         var returnObj = {};
  3.         var searchObj =
  4.             typeof searchDefinition == 'object'
  5.                 ? search.create(searchDefinition)
  6.                 : search.load({
  7.                     id: searchDefinition
  8.                 })
  9.         try {
  10.             log.debug({
  11.                 title: 'remainingUsage for ' + (searchDefinition.title || searchDefinition.type),
  12.                 details: runtime.getCurrentScript().getRemainingUsage()
  13.             });
  14.             var pagedResults = searchObj.runPaged({
  15.                 pageSize: 1000
  16.             });
  17.         } catch (e) {
  18.             var searchName = searchObj.title || searchObj.searchType;
  19.             log.emergency('Failed to run search in search utils for ' + searchName, e.message);
  20.             return returnObj;
  21.         }
  22.         var pageRanges = pagedResults.pageRanges;
  23.         for (var index in pageRanges) {
  24.             var resultSet = pagedResults.fetch({
  25.                 index: index
  26.             }).data;
  27.             for (var result in resultSet) {
  28.                 var key = Number(index) * 1000 + Number(result);
  29.                 var resultLine = resultSet[result].toJSON().values;
  30.                 //remove arrays from the results
  31.                 for (var property in resultLine) {
  32.                     if (typeof resultLine[property] == 'object') {
  33.                         if (resultLine[property].length == 0) {
  34.                             resultLine[property] = { value: '', text: '' }
  35.                         } else if (resultLine[property].length == 1) {
  36.                             resultLine[property] = resultLine[property][0];
  37.                         } else {
  38.                             tempResultLineObj = {};
  39.                             for (var multiSelectIndex in resultLine[property]) {
  40.                                 tempResultLineObj[multiSelectIndex] = resultLine[property][multiSelectIndex];
  41.                             }
  42.                             resultLine[property] = tempResultLineObj;
  43.                         }
  44.                     }
  45.                 }
  46.                 returnObj[key] = resultLine;
  47.             }
  48.         }
  49.         return returnObj;
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement