record.submitFields() not working in catch(e){ } b...
# suitescript
n
record.submitFields() not working in catch(e){ } block in my M/R script. trying to set any script processing errors in a custom text field field on the record being processed instead of having to sift though script execution logs. Will record.submitFields() not work in a catch statement?
b
should work fine unless you ran out of points
n
it logs any error just fine in in my context.write() log. I don't think I am out of governance points..
that is also in the catch block context.write({ key: 'map stage error (context.write log)', value: e.message });
b
what does the rest of the code look like
t
I believe that if you have declared your object used for the record.load in the try block, that would mean that the variable is not in scope of once you get to the catch block. If you declared the object outside the try block, you should be able to use it both in the try and catch blocks.
n
the record object is loaded outside of the try block
message has been deleted
@battk @Th3VanMan the context.write() inside the catch block always works but the record.submitFields() is not executing
I am using SS 2.1
b
your error handling code has no error handling
n
@battk should I move the record.submitFields() into the summarize function? if not what do you suggest I do?
I know that error handling is a bit different in 2.1 vs 2.0. still trying to get my head around it
b
it isnt
you think your code isnt running, but the more likely answer is that it is throwing an error
and your code isnt good enough to detect it
which is why i told you to log errors in your summarize function
n
that context.write() in my map stage is working as it should and logging any and all errors, that are getting passed to the summarize stage already. my problem is definitely not being aware of any errors. the problem is posting the error to the specific record it is processing via the record.submitFields()
b
implement the logging i linked you
t
I see in you are referencing the packingListId in the catch block. you have that variable declared in the Try block. That variable is not in scope to be used in the catch block. Declare that variable befor the try block, assign it's value in the try block, then you can use it in the catch block.
insert let packingListId = '' before the try. Then line 78 should read packingListId = value.id
@NetSweetie javascript is very particular when it comes to variable scope
n
@Th3VanMan That is what I needed to hear. thank you
s
I think tools like ESLint’s block-scoped-var rule will catch problems like this. A good linter will catch a lot of mistakes and save you considerable time avoiding bugs in the long run.