This topic contains 3 replies, has 0 voices, and was last updated by pcutler 7 years ago.
-
AuthorPosts
-
October 24, 2017 at 3:02 pm #17873
northern_brewerThe code sample in the docs seems incomplete.
It says you can create a UserEventError like so:
Code:
require([‘N/error’],
function(error) {
function createError() {
var errorObj = error.create({
name: ‘MY_CODE’,
message: ‘my error details’,
notifyOff: true }); }
createError(); });
But this only creates the error object.Is the next step to “throw errorObj;” ??
When I do this, the UI returns a SuiteScriptError, not a UserEventError. Am I missing something?
This is a cached copy. Click here to see the original post. -
October 24, 2017 at 3:40 pm #17874
erictgrubaughA UserEventError will only be thrown if the Error is thrown from a User Event Script; any other time, it will be a SuiteScriptError.
-
October 25, 2017 at 7:33 am #17875
northern_brewerI am throwing my UserEventError from a User Event Script.
My script does some validation on sales orders, and runs “Before Save”. If certain validation checks fail, I would like to throw a UserEventError to indicate that there are validation problems with the sales order.
So I construct an error as in the post above, and then throw it. The UI then displays what appears to be a SuiteScriptError (not a UserEventError):
Code:
{“type”:”error.SuiteScriptError”,
“name”:”MY_CODE”,
“message”:”my error details”,
“stack”:[
“createError(N/error)”,
“validateBrand(/SuiteScripts/validateBrand.js:83)”,
“createError(N/error)”],
“cause”: {
“name”:”MY_CODE”,
“message”:”my error details”,
“notifyOff”:false},
“id”:””,
โโโโโโโ”notifyOff”:false}
In SuiteScript 1 I can create an error, and it looks much nicer. For example, the message is not wrapped in JSON code. -
October 25, 2017 at 7:49 am #17876
pcutlerIf your only goal is improving the way the error message displays on the screen, you can throw a string:
Code:
throw ‘my error’; -
AuthorPosts
You must be logged in to reply to this topic.