i badly need to join multiple searches in NetSuite...
# general
j
i badly need to join multiple searches in NetSuite (joins which are not available in netsuite) - whats the best way to do it ? - do you iterate through each result ? - do you create json out of search results and then join ? do you split results into multiple arrays and then process ? i tried using json but NetSuite search structure is nested and unnecessarily complicated, also NetSuite search object columns do not have data types, any one having any experience or share code would be greatly helpful
b
this sounds like a #C29HQS63G question, but you might want to give more details about what you want for your output
j
yes its a suitescript question for sure - will move it there
d
@battk I didn't look hard enough for this question in #C29HQS63G, but did you get an answer yet? I've been using this pattern with lodash:
Copy code
_.map(array, function(element){
  _.find(otherArray, function(otherArrayElem){
	return it if found
  }
  _.assign(sourceArray, value);
}
b
@j.j
j
thanks @battk and @dbaghdanov - will this work with nested JSON elements - the issue with NetSuite is search result to json gives nested json, i think netsuite should provide a better library to join query searches or manipulate search result object and output as json xml csv pdf table list html etc. that would make life easier, else we have to manually parse results and use external libraries everytime and write code for each time
d
yes, I was just using this "pattern" for a project last week, where I had multiple search result sets, but could not join them in the same saved search. I built out the search results independently, something like:
Copy code
var resultSet1 = [];
search.run().each(function(result){ resultSet1 .push(result.ToJSON()); return true; });
var resultSet2 = [];
otherSearch.run().each(function(result){ resultSet2.push(result.ToJSON()); return true; } );
and then you can apply that:
Copy code
_.map(resultSet1, function(r1elem){
  _.assign(resultSet1, _.find(resultSet2, function(r2elem){ return r1.elem.values.customfield == r2elem.values.othercustomfield;