How to trigger a script when saving an entity

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mliebherr99
    Junior Member
    • Oct 2021
    • 7

    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
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Hi Michael,

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

    Or utilize formula https://docs.espocrm.com/administration/formula/
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • mliebherr99
      Junior Member
      • Oct 2021
      • 7

      #3
      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

      Comment

      Working...