Email Address and Phone Number value object field types

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aldisa
    Junior Member
    • Jun 2023
    • 28

    Email Address and Phone Number value object field types

    I am little confused by the Value Objects explanations on this page:

    The example for Email Address and Phone Number value objects shows this:
    PHP Code:
    <?php
    
    $emailAddressGroup = $accountEntity->getEmailAddressGroup();
    
    $primary = $emailAddressGroup->getPrimary();
    
    $modifiedEmailAddressGroup = $emailAddressGroup
        ->withAddedEmailAddress(
            EmailAddress::create('address@test.com')->optedOut()
        );
    
    $accountEntity->setEmailAddressGroup($modifiedEmailAddressGroup);
    I have a custom entity ('MyEntity') with this in its entityDefs:
    PHP Code:
    {
      "fields": {
            "phoneNumber": {
                "notStorable": true,
                "type": "phone",
                "typeList": [
                    "Patient",
                    "Dr. Office",
                    "Event Location",
                    "Site Contact"
                ],
                "defaultType": "Patient",
                "required": false,
                "tooltip": false,
                "customMask": "(999) 999-9999"
            },
       }
    } 
    
    But I get an error if I try to this:
    PHP Code:
    $myEntity = $entityManager->getEntityById('myEntity', 'id-string');
    $phoneNumberGroup = $myEntity->getPhoneNumberGroup(); 
    
    Also, how do I add a phone number to a new record for this entity?
  • yuri
    Member
    • Mar 2014
    • 8455

    #2
    You need to define getEmailAddressGroup method in your entity class. Just copy it from another class where it exists.

    If you get any errors and seek help on the forum, it's reasonable to provide error details.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • aldisa
      Junior Member
      • Jun 2023
      • 28

      #3
      My apologies yuri.

      It is a function not found error as follows:

      PHP Code:
      Call to undefined method Espo\Core\Templates\Entities\BasePlus::getPhoneNumberGroup() 
      
      The following does work, however:

      PHP Code:
      $phoneNumberGroup = $myEntity->getValueObject('phoneNumber'); 
      
      As a follow up question, when I am creating a new record, do I need to create the record BEFORE I add the value object?

      For example, can I do this:

      PHP Code:
      $myEntity = $entityManager->getNewEntity('MyEntity');
      $myEntity->set('phoneNumber', 
          new \Espo\Core\Field\PhoneNumberGroup(
              \Espo\Core\Field\PhoneNumber::create('123456789')
          )
      );
      $entityManager->saveEntity($myEntity); 
      
      or do I need to create/save the Entity first before I can add the value object to the Entity object?

      Comment

      Working...