Showing Error Message in User Event script in User Friendly Manner

In User Event scripts , if we throw errors it will be displayed as below, which is not at all user friendly

We can make it better by adding the below code snippet to throw the error:

var err = error.create({ name: 'ITEM_ADDITION_RESTRICTED', message: 'The sales order cannot be updated with new items!' })
    err.toString = function () { return err.message };
    throw err;
}
This will show error message as follows:

Leave a comment

Your email address will not be published. Required fields are marked *