I am using before_save hook and running some data validation. How do I customize standard message āError occurred while saving recordā when I throw an exception due to data being invalid?
Tried SugarApplication::appendErrorMessage(āā¦ā) but it didnāt help.
Could you also advise on how to use LBL_MY_CUSTOM_ERROR in the code once it is defined? Is it passed to exception or need to be set in some global variable?
class CustomLogic
{
public function validateResult($bean, $event, $arguments)
{
$errorMessage = translate('LBL_MY_CUSTOM_ERROR', 'YourModule');
throw new Exception($errorMessage);
}
}
I need to be able to restrict Account editing based up on role or security group. Is it possible to do it on the front end? I thought it is not thatās why I was doing backend validation.
Sure @pgr, I will try to help. We have a role based ACL which can help to restrict editing and saving based on custom roles. We can create a custom role and set restrictions for the required modules from the admin panel. If this is not feasible, then we can achieve the required functionality through defining custom validators and registering in validation manager by writing Angular Typescript code OR implementing a Process Handler in PHP code. But that depends upon the type of validation. If the validation is related to field like integer, phone, required , readonly etc. We can have a common generic validator. Or it is business validation, the process handler would help. @amsl can you please help understand your validation requirement ? is it a field or business rule that checks a set of fields before saving the record? Also please specify which version you are using. Version 8.8 has some way to extend the save action.
Thank you very much for your response. We are using 8.7 so maybe updating to 8.8 is the first step.
As far as business logic itās pretty simple. We need to prevent some set of users from modifying certain fields for Accounts. For example only users that belong to security group A (lets call them admins) can modify custom drop down and check box fields. All fields should be visible to everyone. Doing it via roles or security group is fine for us but we need to being able to prevent saving or make field read only if user does not have permission do perform edit.
Custom error message on save and aborting the operation is fine as well as a solution for us if there is no better one.
This doesnāt look impossible, We can get there by adding a new logic type for āreadonlyā and use the key in fields definitions logics to restrict. There may be some better solutions. For now I think we can display the fields in detail page and set the display off in edit mode using ādisplayTypeBackendā where the process handler will take care of returning value āshowā or ānoneā depending upon the current user role or the required business logic. I am working on the āreadonlyā logic type in extensions and will share after completing the code. Thanks
Got the same basic requirement, just match a regex or a custom validation on a specific field, throw a custom error message and roll back to old value if the validation is not meet.
old V7 hook work, only the custom error message cant be display for some reason. also :
This could help but without a proper example its hard to make it to work.
Im trying to find out how the default one for mail & phone number is set up to replicate it