Announcement

Collapse
No announcement yet.

How to trigger a script when saving an entity

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    Hi Michael,

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

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

    Comment


    • #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...
      X