How to trigger a script when saving an entity

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • mliebherr99
    replied
    ok, so i created: custom/Espo/Custom/Hooks/Connection/MyHook.php

    With the code example from https://docs.espocrm.com/development/hooks/

    => tha gives me "PHP Parse error: syntax error, unexpected ':', expecting ';' or"..

    So i changed the code from:
    PHP Code:
      public function beforeSave(Entity $entity, array $options): void 
    
    to:
    PHP Code:
       public function beforeSave(Entity $entity, array $options) 
    
    Now i get:
    PHP Fatal error: Call to undefined method Espo\Custom\Hooks\Connection\MyHook::getDependency List() in /data/webs/test_espocrm/webroot/application/Espo/Core/HookManager.php on line 128

    My Hook looks like:


    PHP Code:
    <?php
    namespace Espo\Custom\Hooks\Connection;
    
    use Espo\ORM\Entity;
    
    class MyHook
    {
    // optional parameter, defines in which order hooks will be processed
    // less value means sooner
    public static $order = 5;
    
    public function beforeSave(Entity $entity, array $options)
    {
    }
    
    }
    
    
    ?>

    I am using EspoCRM Version 5.5.6

    Any hints?

    Cheers,
    Michael

    Leave a comment:


  • yuri
    replied
    Hi Michael,

    Create afterSave hook https://docs.espocrm.com/development/hooks/

    Or utilize formula https://docs.espocrm.com/administration/formula/

    Leave a comment:


  • mliebherr99
    started a topic How to trigger a script when saving an entity

    How to trigger a script when saving an entity

    Hello,

    we manage some customer connections in espo with an entity. Looks like: https://espocrm.foo.bar/#Connection/...35f62c14c2a9dc

    How can i trigger a script when adding/changing an entity?

    Cheers,
    Michael
Working...