Workflow Wont Trigger

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • boCyrill
    Junior Member
    • Jun 2020
    • 23

    Workflow Wont Trigger

    Hi All,

    I have a module with a "many to many" relationship field.
    I would like to run a service when new record is linked to this entity.
    I have used the "After record updated" trigger type.
    When I update any field, the workflow runs well but when I link a new record of the many to many relationship, it does not trigger the workflow.
    How is this supposed to be done please?

    Thank you in advance
  • item
    Active Community Member
    • Mar 2017
    • 1476

    #2
    Hello,

    not really study this case but you can do so :
    in hook (need coding)
    afterRelate,
    afterUnrelate



    just save entity... so workflow certainly trigger.


    Maybe a feature request if not exist
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    • boCyrill
      Junior Member
      • Jun 2020
      • 23

      #3
      item it worked like a charm
      Thanks for the clue.

      For those who may be stuck in the same situation, here is my working code. You can customize as you wish.
      namespace Espo\Custom\Hooks\Resume;

      use Espo\ORM\Entity;

      use Espo\Core\{
      ORM\EntityManager,
      };

      class ResumeJobCategory extends \Espo\Core\Hooks\Base {
      protected $entityManager;

      public function __construct(EntityManager $entityManager) {
      $this->entityManager = $entityManager;
      }

      public function afterRelate(Entity $entity) {
      $entity->set("lastJobCatRelateTime", time());
      $this->entityManager->saveEntity($entity);
      }

      public function afterUnrelate(Entity $entity) {
      $entity->set("lastJobCatRelateTime", time());
      $this->entityManager->saveEntity($entity);
      }
      }

      Comment

      Working...