Announcement

Collapse
No announcement yet.

AfterSave Event Hook

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

  • AfterSave Event Hook

    I want to make a Hook to handle "afterSave" event for getting the attached "Worklogs" entity [as comments] attached to another "AccountOpening" entity. I made this code but It didn't run:

    $entityManager = $this->getEntityManager();
    $account = getEntity('Account', $accountId);
    $record = $entity->get('id');
    $parentAccountOpening = $entity->get('id');
    $relatedAccountOpening = $entity->get('accountOpeningsIds');

    $list = $entityManager->getRepository('AccountOpening')->findRelated($entity, 'workLogs');
    $listA = $list->toArray();
    for($i = 0 ; $i < count($listA) ; $i++){
    $entity->set('description' ,$listA[$i]);
    }


    and tried another way but also not successful:

    $accountOpening =$entityManager->getRepository('WorkLog')->find();
    $workLogs = $entityManager->getRepository('AccountOpening')->findRelated($entity, 'workLogs');
    $entity->set('description', $workLogs->id);

  • #2
    These might help you:
    https://www.espocrm.com/documentatio...lopment/hooks/
    Job Offers and Requests

    Comment


    • DevMostafa
      DevMostafa commented
      Editing a comment
      I did manage to access this url

      but the parent url didn't open, So I think it is a private (not public) url.
      I want to ask you if there's a full Development documentation to browse it.
      I made this code and I think it runs now successfully, but I'm enhancing now the trigger event time.

      $recordId = $entity->get('id');
      $entityManager = $this->getEntityManager();
      $workLog = $entityManager->getRepository('WorkLog')->where(array(
      'id' => $recordId,
      ))->findOne();

      $text = null;
      $accountOpening = $entityManager->getRepository('WorkLog')->
      findRelated($workLog, 'accountOpening');

      if(isset($accountOpening)){
      for($i = 0 ; $i< count($accountOpening) ; $i++){
      $text.= ",".$accountOpening[$i]->id;
      }
      }
      $entity->set('firstName', $text );

  • #3
    Here is documentation on github https://github.com/espocrm/documenta...er/development.
    Job Offers and Requests

    Comment


    • #4
      Thanks Tarasm for your help

      Comment

      Working...
      X