Announcement

Collapse
No announcement yet.

Update Contact Email Using Formula

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

  • Update Contact Email Using Formula

    Hi,

    We have a strange case. We have a varchar field called "VIP Email" at the Contacts module.

    We have created a simple formula that copies the value of VIP Email into the contact's email field (check attachment).

    Code:
    emailAddress=vipmail;

    However, each time we create or update a contact, the contact's email is NOT updated. We have also tested in the demo of EspoCRM but we get the same result.

    Are we doing anything wrong?

    Thanks a lot for your time.

  • #2
    Hello,
    it's not strange .. i think it's "normal" and it's perfect so

    this work on backEnd.. don't know on formula :

    PHP Code:
    $o = (object) [
    'emailAddress' => $email,
    'primary' => true,
    ];

    // and then

    $user->set([
    'userName' => $userName,
    'salutationName' => 'Mrs.',
    'firstName' => $firstName,
    'lastName' => $lastName,
    'type' => 'regular',
    'isAdmin' => 0,
    'isActive' => $isActive,
    'gender' => 'Female',
    'emailAddressData' => [$o],
    'assignedUserId' => '1'
    ]); 

    Comment


    • #3
      Hi item ,

      Thanks for the help. However, I don't think it's what I'm looking for.

      Is there any way to update the emailAddress field using the entity's formulas from the admin panel?

      Thanks.

      Comment


      • #4
        Hi Pablo,

        Espocrm email address field is not a simple varchar, so cannot directly write to the "emailAddress" you only can read from it because it is calculated from the linked emails array (the primary one).

        To set the email address you need to work with "emailAddressData" as item mentioned above :

        NOTE: this will overwrite the data you insert in the form email field.
        Click image for larger version  Name:	Screen Shot 2020-10-20 at 8.45.40 AM.png Views:	0 Size:	44.3 KB ID:	63752

        Attached Files
        Last edited by eymen-elkum; 10-20-2020, 09:34 AM.
        CEO & Founder of Eblasoft.
        Professional EspoCRM development & extensions.

        Comment


        • eymen-elkum
          eymen-elkum commented
          Editing a comment
          Actually it is worked here, I also was surprised!

        • eymen-elkum
          eymen-elkum commented
          Editing a comment
          I confirm it is working on the version 6 beta, not tested on previous versions

        • espcrm
          espcrm commented
          Editing a comment
          Imagine if it considered a bug and loophole get fix XD

      • #5
        Hi eymen-elkum ,

        Thanks for the help. As yuri said, it didn't work on version 5.9.3.

        "Though it's possible to unset emailAddressData to avoid re-writing by the value passed from the form."
        yuri: Any tips to unset emailAddressData using a formula?

        ​​​​​​​Thanks a lot.

        Comment

        Working...
        X