Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.runPaged = function (searchDefinition) {
- var returnObj = {};
- var searchObj =
- typeof searchDefinition == 'object'
- ? search.create(searchDefinition)
- : search.load({
- id: searchDefinition
- })
- try {
- log.debug({
- title: 'remainingUsage for ' + (searchDefinition.title || searchDefinition.type),
- details: runtime.getCurrentScript().getRemainingUsage()
- });
- var pagedResults = searchObj.runPaged({
- pageSize: 1000
- });
- } catch (e) {
- var searchName = searchObj.title || searchObj.searchType;
- log.emergency('Failed to run search in search utils for ' + searchName, e.message);
- return returnObj;
- }
- var pageRanges = pagedResults.pageRanges;
- for (var index in pageRanges) {
- var resultSet = pagedResults.fetch({
- index: index
- }).data;
- for (var result in resultSet) {
- var key = Number(index) * 1000 + Number(result);
- var resultLine = resultSet[result].toJSON().values;
- //remove arrays from the results
- for (var property in resultLine) {
- if (typeof resultLine[property] == 'object') {
- if (resultLine[property].length == 0) {
- resultLine[property] = { value: '', text: '' }
- } else if (resultLine[property].length == 1) {
- resultLine[property] = resultLine[property][0];
- } else {
- tempResultLineObj = {};
- for (var multiSelectIndex in resultLine[property]) {
- tempResultLineObj[multiSelectIndex] = resultLine[property][multiSelectIndex];
- }
- resultLine[property] = tempResultLineObj;
- }
- }
- }
- returnObj[key] = resultLine;
- }
- }
- return returnObj;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement