Anyone solved the issue about using multiple formu...
# suitescript
d
Anyone solved the issue about using multiple formula fields in a search-based Map/Reduce
b
use different names for your formulas
formulatext_0
instead of
formulatext
a
No need to use hardcoded reference to the formulatext columns, you can do something like this:
Copy code
var aColumns = [];
var oColumnsDefinition = {};
for (var sKey in COLUMNS_MAP) {
   oColumnsDefinition[sKey] = search.createColumn(COLUMNS_MAP[sKey]);
   aColumns.push(oColumnsDefinition[sKey]);
}
b
that strategy will not work in the map or reduce state after the search results are stringified
a
They will if you properly handle your searches in the getInput stage... returning raw result object and accessing hardcoded properties is far from being a good practice...
b
you will have to make a very good argument when NetSuite's best practices says otherwise
a
I'm aware of that document and also aware of another 30+ crappy/bad SuiteAnswers, NetSuite is not exactly consistent per say, if netsuite changes the underlaying result object structure at any given moment which they can do and updates the "methods"
result.getValue
and
result.getText
any script passing or using the raw result object will break and any script using the official API methods will prevail. I don't know what makes people happy, but I know what makes me happy, knowing that 5+ years old MR never returned to me after ~10 NetSuite releases.
From a data structure or software design perspective that best practice of using the raw result object structure when there are defined and documented official API methods is terribly wrong.
b
the json that you see from the result object is not the underlying structure, its the output of a .toJSON method. If NetSuite changed the underlying data structure, they can change the code of the .toJSON method to still output the old representation
a
Or they may not since
.toJSON
is not officially documented anywhere as far as I know? Right?
b
my argument is more that the hypothetical problem has a hypothetical solution
netsuite can update .toJSON along with getValue and getText and there will be no problem
👍 1
k
Its a bit slower but you could run the search in the get input and cast the columns in the map phase. Alternatively you return from get Input just the internal id and in the map phase run the search again. Nothing is ideal, just work arounds
d
Thanks everyone for the feedback