Announcement

Collapse
No announcement yet.

Meeting hook works only from main entity create button

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

  • Meeting hook works only from main entity create button

    I'm seeing some unusual behavior when using a beforeSave in a hook for meetings. All is working as expected when users create a meeting from the meeting entity, but when a user creates a meeting from the calendar or from the activities section on the account the hook does not run and the actions are not completed. The meeting record itself is being created, however. Is there a way to make sure the hook is running when adding a meeting from the different locations? Do I need to add additional copies of the hook for calendar and account?

  • #2
    Hello
    Sorry, can not reproduce.
    data/cache/application/hooks.php - check, if your hook is here.
    Could you share your hook? And what is the version of your espocrm?

    Comment


    • #3
      Hello Tanya,
      I've sent a pm with my hook. I'm on version 4.8.4. I'm planning to update to 5.0.2 the end of this week. This works great when a meeting is created from the meeting entity, but not from the calendar or account>activites.

      Comment


      • #4
        I've upgraded my version to 5.0.3 successfully. I notice that my hooks for a meeting will only show up if the record is saved twice.

        I wrote a beforeSave hook on meetings to check for the last held meeting and the next planned meeting and to write their ids to two corresponding link fields on both the account entity and a custom prospecting entity. Is that because there is not yet an id associated with the record? Should I be using afterSave instead?

        If I edit the meeting and save it a second time then it seems to work properly.

        Here is my Custom/Hooks/Meeting/MeetingAccount.php

        namespace Espo\Custom\Hooks\Meeting;

        use Espo\ORM\Entity;

        class MeetingAccount extends \Espo\Core\Hooks\Base
        {

        public function beforeSave(Entity $meeting)
        {

        $ID = $meeting->get('id');
        $parentID = $meeting->get('parentId');
        $status = $meeting->get('status');


        //////////////////////////////////////
        //Open connection to Account based on parent id (accountid)
        $accountList = $this->getEntityManager()->getRepository('Account')->where(array(
        'id' => $parentID,
        ))->findOne();
        /////////////////////////////////////

        if ($accountList != ""){
        $accountID = $accountList->get('id');


        ////////////////////////////////////// LAST MEETING
        //Open connection to Meeting based on account id
        //Check for an existing record already in the Meeting Database based on the account_id with HELD status
        $meetingList = $this->getEntityManager()->getRepository('Meeting')->where(array(
        'parentId' => $parentID,
        'status' => 'Held'
        ))->order('dateStart', 'DESC')->findOne();
        ////////////////////////////////////

        ////////////////////////////////////// NEXT MEETING
        //Open connection to Meeting based on account id
        //Check for an existing record already in the Meeting Database based on the account_id with PLANNED status
        $nextMeetingList = $this->getEntityManager()->getRepository('Meeting')->where(array(
        'parentId' => $parentID,
        'status' => 'Planned'
        ))->order('dateStart', 'ASC')->findOne();
        /////////////////////////////////////


        //Open connection to Account based on this account id
        $account = $this->getEntityManager()->getEntity('Account', $accountID);

        /////Update Last Meeting
        if($meetingList != ""){
        $meetingID = $meetingList->get('id');
        $meetingStatus = $meetingList->get('status');
        if($status == 'Held'){
        $account->set('meetingId', $meetingID);
        }
        } else {
        $account->set('meetingId', "");
        }

        /////Update Next Meeting
        if($nextMeetingList != ""){
        $nextMeetingID = $nextMeetingList->get('id');
        $nextMeetingStatus = $nextMeetingList->get('status');
        if($status == 'Planned'){
        $account->set('nextMeetingId', $nextMeetingID);
        }
        } else {
        $account->set('nextMeetingId', "");
        }

        /////Updated record
        $this->getEntityManager()->saveEntity($account);
        }

        }
        }



        ***Note: I removed the option to select a parent other than Account for the meeting. On Account entity, I added 2 custom link fields called meetingID and nextMeetingID. I then modified the entitydefs json for account to display the meeting start date for both of these fields. When searching for the single meetings, I probably should also check for deleted status of 0. This may be helpful code when work with hooks.
        Last edited by joy11; 01-30-2018, 07:34 PM.

        Comment


        • #5
          In beforeSave method, if you want to get related meetings for account, current meeting not exists.
          And set all needed parameters to method, because after upgrade php you can get fatal error.

          Comment


          • #6
            I'm not sure I understand. I should mention that I've modified meeting to only have parent as account or null. Should I be performing this as afterSave?

            Comment


            • #7
              Should I be performing this as afterSave? - Yes

              Comment


              • #8
                I changed it to afterSave and it works beautifully.

                Comment

                Working...
                X