i have 5 parsedValues of a saved search. in the 5,...
# suitescript
v
i have 5 parsedValues of a saved search. in the 5, i need to compare on subsidiary and group into one and then create a journal record per subsidiary. what logic should i use in that? i thought of nested for loop, is there any suitescript functionality?
n
Copy code
let subsidiaryObj = {}; // initialized an object that we will use to group eveything by subsidiary

// run the saved search and loop through the results
savedSearchObj.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);
});
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