This topic contains 3 replies, has 0 voices, and was last updated by pcutler 7 years ago.

  • Author
    Posts
  • #17873

    northern_brewer

    The 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.

  • #17874

    erictgrubaugh

    A UserEventError will only be thrown if the Error is thrown from a User Event Script; any other time, it will be a SuiteScriptError.

  • #17875

    northern_brewer

    I 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.

  • #17876

    pcutler

    If your only goal is improving the way the error message displays on the screen, you can throw a string:

    Code:
    throw ‘my error’;

You must be logged in to reply to this topic.