Hello everyone! Does anyone know how to `context.w...
# suitescript
j
Hello everyone! Does anyone know how to
context.write()
in a MapReduce using 2.1 api? Just returning an object with a key/value pair does not seem to be working. The reduce function doesn’t even start! The object
mapContext
provided doesn’t have a
write
function…
d
it should be
Copy code
function map(context) {
  // Your code
  
  context.write({ key: "your key", value: "your value" })
}
j
Yeah.. thats for 2.0.. In 2.1 we have
const map = (mapContext) => { ....
d
2.1 is the same
I yoinked this example from a working 2.1 script
you dont have to use arrow functions in 2.1, you can still use the
function map(mapContext) {}
syntax
b
you are officially doomed if your mapContext does not have a write function
that said, how are you determining that there is no write function
d
my guess is through JSON.stringify(), and then functions dont show
j
The entry points in 2.1 look more like:
Copy code
const getInputData = (inputContext) => {
const map = (mapContext) => {
const reduce = (reduceContext) => {
const summarize = (summaryContext) => {
At least these were given by the IDE… So you’re saying that i can just forget the arrow function and write like its 2.0?
d
Yes that should work
Those entry points as given by your IDE should also work, so chances are the issues lies elsewhere. In your original message you used
write.context()
as example which will never work. Instead do
context.write()
or
mapContext.write()
depending on the parameter name
j
Yes I meant
context.write()
🤦🏾‍♂️ just wrote wrong here. The object
context
doesn’t exist using the arrow function since
mapContext
is given and for
mapContext
the function
write()
doesn’t exist.. If I change the entry points declarations to functions instead arrows I expect to have a
context
object as usual.
I changed the entry point declarations and it worked.. Thank you @Diderik!
d
That is very weird, I'm suprised the context given is different between normal and arrow functions. But glad you got it working!
w
@Juliano Oliveira if you mean that it doesn't exist just because webstorm says so, then ignore that. I have used webstorms sdf-templates successfully
j
Hi @Watz, actually the error came from NetSuite when running.. Did you manage to make it work?
w
Yes.
j
ok, I’ll go ahead with my current version and will try to refactor again after finished.
w
if it works for you, leave it be. I don't think it will matter.