0
votes

I want to prevent a record from being deleted based on certain conditions in NetSuite. However, I can't seem to find a failure event on validation? BeforeSubmit on a UserEvent has a delete type, but it doesn't have a return value for the function, so I can't just say return false, can I?

How do I then prevent the deletion of a record, or fail a record submission of a certain type?

4

4 Answers

7
votes

Instead of returning false, just throw an error. Not user friendly but it is the only option, as far as I know.

Since it is in the Before Submit User Event, the submission or deletion will fail.

1
votes

You'll want to use a beforeSubmit user event script and throw an error using nlapiCreateError. Here's an example:

function beforeSubmit(type) {
  if(type == 'delete') {
    // NOTE `nlapiGetFieldValue` returns nil/empty during a delete event
    //      `nlapiGetOldRecord` needs to be used to pull the entire record

    var payment = nlapiGetOldRecord();

    if(payment.getFieldText('paymentmethod') == 'cash') {
      throw nlapiCreateError(
        'AN_ERROR',
        'Message to the user!',
        true
      );
    }
  }
}
1
votes

You can also use a Workflow to prevent the Delete button to display to the user:

enter image description here enter image description here

0
votes

You could add client-side code to pop up a message to the user when trying to delete a record you want to prevent. With that said, you would still want to put a UserEvent script preventing the delete actions as well. This would prevent the user from by passing the restriction