diff --git a/lib/saved_search.js b/lib/saved_search.js index bfa50fc..ef67197 100644 --- a/lib/saved_search.js +++ b/lib/saved_search.js @@ -158,7 +158,35 @@ this.SavedSearch = (function() { * @return {null} */ SavedSearch.prototype.appendResults = function(resultsBlock) { - this.results = this.results.concat(resultsBlock); + var newResultsBlock = []; + for ( var i = 0; resultsBlock != null && i < resultsBlock.length; i++ ) + { + var newResult = {"id":resultsBlock[i].getId(), "recordtype":resultsBlock[i].getRecordType(), "columns":{}}; + var result = resultsBlock[i]; + var columns = result.getAllColumns(); + var columnLen = columns.length; + + for (x = 0; x < columnLen; x++) + { + var column = columns[x]; + var name = column.getName(); + var label = column.getLabel(); + var join = column.getJoin(); + var value = result.getValue(column); + var text = result.getText(column); + var joinTitle = join + 'Join'; + var columnTitle = (label ? label : name); + if(text && (text !== value))var columnData = {'name':text, 'internalId':value}; + else columnData = value; + if(join && !label){ + if(!(joinTitle in newResult.columns))newResult.columns[joinTitle] = {}; + newResult.columns[joinTitle][columnTitle] = columnData; + } + else newResult.columns[columnTitle] = columnData; + } + newResultsBlock.push(newResult); + } + this.results = this.results.concat(newResultsBlock); } /** diff --git a/lib/search.js b/lib/search.js index 77e5098..c4c565b 100644 --- a/lib/search.js +++ b/lib/search.js @@ -325,7 +325,35 @@ this.Searcher = (function() { * @return {null} */ Searcher.prototype.appendResults = function(resultsBlock) { - this.results = this.results.concat(resultsBlock); + var newResultsBlock = []; + for ( var i = 0; resultsBlock != null && i < resultsBlock.length; i++ ) + { + var newResult = {"id":resultsBlock[i].getId(), "recordtype":resultsBlock[i].getRecordType(), "columns":{}}; + var result = resultsBlock[i]; + var columns = result.getAllColumns(); + var columnLen = columns.length; + + for (x = 0; x < columnLen; x++) + { + var column = columns[x]; + var name = column.getName(); + var label = column.getLabel(); + var join = column.getJoin(); + var value = result.getValue(column); + var text = result.getText(column); + var joinTitle = join + 'Join'; + var columnTitle = (label ? label : name); + if(text && (text !== value))var columnData = {'name':text, 'internalId':value}; + else columnData = value; + if(join && !label){ + if(!(joinTitle in newResult.columns))newResult.columns[joinTitle] = {}; + newResult.columns[joinTitle][columnTitle] = columnData; + } + else newResult.columns[columnTitle] = columnData; + } + newResultsBlock.push(newResult); + } + this.results = this.results.concat(newResultsBlock); } /**