how to prevent saving in before submit you would ...
# ask-stanley-ai
n
how to prevent saving in before submit you would need to throw an uncaught error. It's ugly but works. You could potentially on Create intercept the save, re-direct to the record, which would avoid changes being saved and in beforeLoad display a banner type message.
c
AI generated answer (using internal Slack threads):
In order to prevent a record from being saved in a User Event Before Submit, you would need to throw an uncaught error. This method might not be the most elegant, but it is effective. Here is an example of how you can do this:
Copy code
javascript
function beforeSubmit(context) {
    throw nlapiCreateError('E999', 'You cannot save this record.', true);
}
This will stop the record from being saved and display the error message 'You cannot save this record.' to the user. Unfortunately, you cannot show a popup message in a User Event Before Submit. Popups can only be shown in a Client Script, specifically in the
onSave
event. However, you can display a banner type message in the
beforeLoad
event. If you want to redirect the user to a different page, you can use the
nlapiSetRedirectURL
function in the
afterSubmit
event. However, if an error is thrown in the
beforeSubmit
event, the
afterSubmit
event will not run. If you need to validate the record in the
beforeSubmit
event and prevent the save operation, you can throw an error. However, the error message displayed by NetSuite might not be user-friendly. You can use a Client Script's
saveRecord
function paired with the
N/ui/dialog
module to display a more user-friendly message. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.876268923
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.856045
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.846936345
Please provide your feedback on this answer.