retrieve saved search results from suitescript. sa...
# ask-stanley-ai
e
retrieve saved search results from suitescript. saved search results are group
c
AI generated answer (using internal Slack threads):
To retrieve saved search results from SuiteScript where the saved search results are grouped, you can use the
search
module in SuiteScript 2.0. Here is a general example of how you can do this:
Copy code
javascript
var mySearch = search.load({
    id: 'customsearch_my_search'
});

mySearch.run().each(function(result){
    // Access your grouped columns
    var column1 = result.getValue(result.columns[0]);
    var column2 = result.getValue(result.columns[1]);
    // Continue for all columns

    // Do something with the values
    // ...

    return true; // Continue to the next result
});
In this example, replace
'customsearch_my_search'
with the ID of your saved search. The
result.getValue(result.columns[n])
lines are where you retrieve the values of your grouped columns. Replace
n
with the index of the column you want to retrieve. If you want to group your results by a specific field, such as subsidiary, you can use an object to store your results grouped by that field. Here is an example:
Copy code
javascript
let subsidiaryObj = {}; // initialized an object that we will use to group everything by subsidiary

// run the saved search and loop through the results
mySearch.run().each((result) => {
  // get the subsidiary from the result
  let subsidiary = result.getValue({ name: 'subsidiary' });

  // if the subsidiary is not in the object, add it
  if (!subsidiaryObj[subsidiary]) {
    subsidiaryObj[subsidiary] = [];
  }

  // push the result id to the array
  subsidiaryObj[subsidiary].push(result.id);

  return true; // Continue to the next result
});
In this scenario after the search loop runs you would have an object named
subsidiaryObj
that lists each unique subsidiary as a key with the value being an array of record id's from the search. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.833496094
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.829101562
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.826904297
Please provide your feedback on this answer.
Thank you for your feedback