Prevent save (udpate and create) record under specific condition

Hello to everyone,
I need to prevent save of a record (in create or in edit mode) under specific condition:
I create before_save hook. In the body of the function, I made a db query to check the condition and if the condition is satisfy, prevent the save action and redirect to a URL.
Now, I have this problem: If we are in update mode, if I redirect to a EditView for the same $bean->id I lost the new informations that save operation must override.
If we are in create mode, and redirect to EditView, I reach a page to create a new record with all fields unfill.
How can I mantain the changes without loose all informations that user filled?

Thank you so much for the help,

The better strategy is to inject a validation task at the button save, which should be triggered before saving the own data.


Thank you for your reply.
How can I inject validation task at the button save?
Have you a sample code to do this?

Thank you.

Example of Injecting code into Edit view for validation (any good?)

Example of Injecting code into Edit view for validation (good, and with video)

I keep my list of samples publicly here, in the hope that someday people will start writing technical blog posts in our Documentation site:

1 Like

I have opted for a solution that I found in internet. (the example is for sugarcrm, but I tried it and works for suitecrm too).
Here a link of the example.
I hope that this helps other.


1 Like


I have added that link to my list of tricks/tutorials.

1 Like

Wonderful! I’m very happy than sometimes I can help others with my expirience :slight_smile:


I’d definitely like to have this on the backend, without needing to implement it in JS.

1 Like