Hi All, Need help in the search done in getInputDa...
# suitescript
s
Hi All, Need help in the search done in getInputData() function of MR script. I have used a search on Sales Order, to retrieve 2 formula text columns( both have the same name '*formulatext'*, but with different labels. One for 'itemid' and other for 'unit'). While trying to access the mapContext.values, I observe that only one 'formulatext' field was passed from getInputData() to map(). Not sure if any1 had faced a similar issue. Kindly help me out to access both the 'formulatext' columns in map(). Thanks in advance & Appreciate quick response.
b
whatever NetSuite uses to convert search results into JSON strings isn't smart enough to handle multiple formulas
do the search yourself in getInputData
p
Also, if the search and formulas are trivial and don’t do aggregation, you could instead replicate the formula in the script using the component columns & JS. Obviously not always possible
s
@battk do the search yourself in getInputData. This is not clear. The search is done in the getInputData() which has 2 'formulatext'.
n
turn your search result in to JSON and pass that forward to MAP that way you can dispense with using .getValue etc in MAP as you are no longer working with search result objects
(presumes you know how to access search results that have more than one formula field to create your JSON)
b
share your code
if you run the search yourself getInputData, you shouldnt run into problems
the problem only occurs if you return a search.Search Object or a search.Search Object Reference
it might do it for the query stuff, but i have not tested queries
s
@battk Tried running the search within getInputData() as well. Even this didn't help. Please find the script attached.
b
whoever taught you how to write search code is a terrible person
ill try to avoid that conversation and simply say that your code doesn't return anything in getInputData
s
@battk You can neglect the search filters, it might be bit confusing as we pick filter data from a csv file.
b
its more the usage of both runPaged and run()
you only needed one
but the problem remains, your getInputData returns undefined
s
Currently im not returning the value from getInputData(), i just tried to access the 'itemNumber' and 'units' field from the search result. And still see the values are same for both. Below is the log FYI: soRecId= 366709 | lineUnqKey= 12355182 | itemNumber= Case | order# = 201393 | units= Case
As observed the 'itemNumber' and 'units' values remain the same. But the expected was '28358' and 'Case'.
b
do you want to learn how to get formula columns? or how to pass useful data to map
2 different things at this point
s
I would like to know both. Note: there are 2 formulatext in the column and i need both these values.
FYI: tried using the same search in Schedule script, it work fine.
b
you access formula columns using the the column that was used to create it
if your formula was like
Copy code
var column0 = search.createColumn({
  name: "formulatext",
  formula:
    "case when instr({item.itemid},' : ')!=0 then substr({item.itemid},instr({item.itemid},' : ')+3) else {item.itemid} end",
  label: "Item Number"
});
s
Yes, i do it the same way. If this is not the right method, please provide me some example.
b
then you access it by using
Copy code
var column0Value = result.getValue(column0)
s
Okay, let me try this
b
you can also do
Copy code
var column0Value = result.getValue(search.createColumn({
  name: "formulatext",
  formula:
    "case when instr({item.itemid},' : ')!=0 then substr({item.itemid},instr({item.itemid},' : ')+3) else {item.itemid} end",
  label: "Item Number"
})
you cannot do it like you were doing before without a column object. For example, this will not work:
Copy code
var column0Value = result.getValue({
  name: "formulatext",
  formula:
    "case when instr({item.itemid},' : ')!=0 then substr({item.itemid},instr({item.itemid},' : ')+3) else {item.itemid} end",
  label: "Item Number"
})
s
@battk Thanks a lot, Wow, that worked using this. var column0Value = result.getValue(column0)
Now can i get help on how to pass useful data to map ?
b
return an array of search results
s
Im sorry, I know I'm taking your time. But can I get any example?
b
Copy code
return soSearchObj.runPaged().fetch({index: 0}).data
you can also return the Page if you want to process multiple search results in a map
Copy code
return soSearchObj.runPaged().fetch({index: 0})
if you were writing real code, you would probably want to control the pageSize when using runPaged and you would want to use a looping mechanism to return all your search results
s
@battk Thank you so much for your assistance and your valuable time.