In Hook before*: How to cancel action and other questions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MaxDau
    Member
    • Nov 2022
    • 38

    In Hook before*: How to cancel action and other questions

    How to cancel further execution in a hook and return an error / message?

    beforeSave:
    PHP Code:
    if($dateStart > $dateEnd){
    return ? OR throw ?
    }
    Is there a flow chart somewhere for the processes in CRM? For newcomers to development with EspoCRM it is not so easy to get an overview of what which file/class is for.
    From what I have seen so far, it is absolutely sufficient to limit yourself to the Custom folder. But can I simply change automatically created classes? Can someone tell me what the situation is with the folders?
    Controller looks like entry points for API.
    After that comes the service, which contains the logic, and then entities, which only refers to one record.

    If I want to compare two records then service would be correct, if I want to check the status of a record then entity would be the correct class?

    I guess the Classes folder is for entity independent functions then?

    Thanks for help & time​
  • item
    Active Community Member
    • Mar 2017
    • 1476

    #2
    Hi, maybe :

    Hello, I have some validations to some fields in the beforeSave hook and if the validation fails I want the error message to be show to the user in the UI. I have the following code in the beforeSave hook function: if ($entity->isAttributeChanged('stage') && in_array($entity->get('stage'), ['closed lost',
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    Working...