Map/Reduce getInputData Saved Search w/ Multiple Formulas

I have a saved search with multiple results that are formula(text). I need to process the data from this saved search in a M/R script.

I’m loading the search from a parameter on the script, then passing it from getInputData to map. When I read the mapContext.value, all of the formulatext columns have been collapsed into one in the resultant object because formulatext is not a unique key.

Is there a way to define how the mapContext.value result is formatted? All of the columns have unique labels, so ideally that would be what I’d like it to use. Or really, any other way to tell the system not to use formulatext as the key repeatedly so it doesn’t overwrite the existing data.

If not, are there other ways around this?

Rookie Asked on April 4, 2023 in SuiteScript.
Add Comment
2 Answer(s)
Best answer

There are a few potential solutions to this.  First, are you loading an existing saved search (defined outside of code), or are you building the search directly inside the script?  If you build the search in the script, one of the simpler ways to fix this is by adding a suffix to the column name, for example:   formulatext_one, formulatext_two, or formulatext_display, formulatext_sort.  The best way is to just use your existing unique label as the suffix.  You can use this with any of the formula types.  See the solution here:

Alternatively, you could redefine the saved search as a SuiteQL query, which provides the column resu lts as an ordered array to the map stage.  With SuiteScript 2.1 and destructuring, it’s very easy to assign each column the variable name you want.

Beginner Answered on April 4, 2023.

Thank you! This is exactly what I needed. The search is defined in the UI, but I’m just grabbing the columns array from the search after it’s loaded, renaming the columns, and overwriting the array with the new data. Now everything is flowing into Map correctly.

on April 4, 2023.
Add Comment

Create your data object from the search results data and then return that JSON object for your datasource.

var data = { Field1: resultsColumn1, Field2: resultsColumn2….}


Beginner Answered on April 4, 2023.

Won’t I run into the 1000 record limit SuiteScript has for saved searches in this case?

on April 4, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor