Announcement

Collapse
No announcement yet.

Hook with Phone Number

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

  • Hook with Phone Number

    I'm trying to create a hook to add the primary phone number to the meeting entity. What I'd like to do is pull the phone number for the account and populate a varchar phone field to display on the detail view.

    The issue seems to be with accessing the entity_phone_number table. Is that table mapped differently than the others? Is there a better way to accomplish this?


    Here is the hook that I've created:


    public function beforeSave(Entity $meeting)
    {
    //I have removed other parent options and only have accounts as parent type for meetings
    $accountID = $meeting->get('accountId');

    $phoneList = $this->getEntityManager()->getRepository('EntityPhoneNumber')->where(array(
    'entityId' => $accountID,
    'primary' => '1'
    ))->findOne();

    $phoneNumberID = $phoneList->get('phoneNumberId');

    $phoneNumber = $this->getEntityManager()->getEntity('PhoneNumber', $phoneNumberID);

    $phone = $phoneNumber->get('name');

    //I have created a varchar field named phone to accept the phone number.
    $meeting->set('phone', $phone);
    }
    Last edited by joy11; 07-06-2017, 08:53 PM. Reason: clarified code notes

  • #2
    I recommend you to use formula for Meeting
    It is easier.
    Code:
    phoneNumber=account.phoneNumber;
    but you need to change a core file (it will be changed in the next release as well)
    https://github.com/tanyalei/espocrm/...es/Meeting.php

    Comment


    • #3
      I just updated to the newest version today and tested it out. It works perfectly when I edit single records. I tried to do a mass update and some of the phone numbers matched up and some did not. I'm going to look into it some more but thought I should ask if there is something else I should be doing to tie the action to the record/account.
      Last edited by joy11; 08-08-2017, 08:44 PM.

      Comment

      Working...
      X