Craig
08/07/2024, 11:55 AMShawn Talbert
08/07/2024, 12:54 PMShawn Talbert
08/07/2024, 12:55 PMmap()
phase to translate those into more meaningful names then pass them on to reduce()
Craig
08/07/2024, 2:22 PMCraig
08/07/2024, 2:24 PMShawn Talbert
08/07/2024, 3:54 PMCraig
08/07/2024, 4:38 PMCraig
08/07/2024, 4:43 PMalien4u
08/07/2024, 6:01 PMRick Goodrow
08/08/2024, 1:29 AMN/search.search
variable and returns an associative array. I added useLabelForKey
for your use case, the object keys will be the column labels from the saved search, instead of the field names/joins.
/**
* Get all the results of a saved search returned in an Object array. Object properties are set to the column IDs
* @param {Search} savedSearch The saved search object
* @param {boolean} useLabelForKey Use the Saved Search Label instead of field name for the key
* @param {boolean} getText Also get the text values for each result
* @return {*[]}
*/
const getAllResultsAsObjectArray = (savedSearch, useLabelForKey = false, getText = false) => {
// Initialize the results array
let results = [];
// Run the search and iterate over the results
savedSearch.run().each(function(result) {
// Initialize the object
let resultObj = {};
// Loop over all the columns in the search and set the Object key/value pair
savedSearch.columns.forEach(function(column) {
// Set the key to either the column name or the label
let key = column.name;
if (useLabelForKey) {
key = column.label;
} else if (column.join) {
key = column.join + '.' + key;
}
// build result entry with value of result
let resultEntry = {
value: result.getValue(column),
};
// Optionally also add the text of the result if specified
if (getText) {
resultEntry.text = result.getText(column);
}
resultObj[key] = resultEntry;
return true;
});
// Push onto results array
results.push(resultObj);
return true;
});
return results;
}
Shawn Talbert
08/08/2024, 2:25 PM