How to addValidationTasks to all places where you can edit data

There is a nice write-up for using addValidateTasks https://support.sugarcrm.com/documentation/sugar_developer/sugar_developer_guide_14.0/cookbook/adding_field_validation_to_the_record_view/.

However, as Sugar evolves there are more and more places where data can be edited.

  • create
  • record
  • list
  • preview
  • record view dashlets
  • sub-panels list view
  • tileview
  • etc

If we want to enforce data validation how do we create validation that can span all available views?

 /CC    

  • Hi  ,

    Great minds think alike !!! I was about to post a question about the same thing.

    We are facing the same issue when we want to return an error to the end user before a save, without having to think of ALL the context this save can be done.

       and  , this is really an important concern for your dev partners that should be handle with a straightforward solution that is upgradesafe.

    nb : we were using this trick ( throw an exception in a before save that was interupting the save Can a 'before' logic hook stop processing a bean ) before the 13.0.3 upgrade that disabled this feature

  • Hi,

    We usually do our validation in the field level so it triggers across all views (maybe not all but it covers the typical views like list/record/subpanel). For instance, if we do validation on a dropdown we do the validation task in custom/modules/Accounts/clients/base/fields/enum/enum.js

  • Hi   and thank you for your feedback,

    in our scenario, the required control is more complicated and required to evaluate condition on multiple fields but also other records.

    So it's seems complicated to got a control only at a field level.

    Fred

  • Use Case 1:

    When an Opportunities Sales Stage is changed to Closed Won, we require that at least one Contact be associated to the Opportunity. 

  • Hi   ,

    I had a chat with Engineering and our official answer is, as of today, you'd have to implement your validations per view as per the article Jeff has referenced here. You could also leverage, Dependency actions that can be used to set "validations". Like ReadOnly, SetVisibility, SetRequired. All these can be configured to be triggered on a formula.

    A logic hook is also an alternative with the drawbacks of the UI elements that you'd get with the view validations. 
    We had an issue introduced as part of our PHP8.2 work that was preventing the exception to be propagated to the UI, but that has been fixed and backported to all SugarCloud instances as well as 13.0.4 versions.

    SugarCRM | Principal Developer Advocate

  •  Where can we find documentation on how to use an Exception in a LogicHook to be triggered to the UX?

    Again this must work for

    all edits on a record. 

    Example Use Case:
    If an Opportunity is set to Closed Won, the opportunity must have at least one contact associated to the Opportunity. Dependencies do not provide this functionality.  

  •  there is no such version as 13.0.4

  • Hi  ,

    Unfortunately we don't have any official documentation to this "hidden feature" of Sugar.

    It is supposed to be as simple as throwing an exception in your logic hook before_save. 

    Make sure it is not "Throwable" which will be catched and logged in sugarcrm.log instead.

    ====

    Also, I apologies, we have backported to 13.1/2/3 and it is also available on 14.0 the fix for propagating the exception to the UI.

    You can take a look at include/utils/LogicHook.php on method public function process_hooks($hookArray, $event, $arguments).... 

    SugarCRM | Principal Developer Advocate