No announcement yet.

Question regarding entity formula

  • Filter
  • Time
  • Show
Clear All
new posts

  • Question regarding entity formula


    we are currently testing Espo for our company and it looks great so far – Espo is really smart and intuitive! But we need a certain functionality to make it perfect for our needs:

    If a new email comes in via any personal or group email account, it should be checked if the sender's email address is already known to Espo in any contact, account, opportunity or lead (NOT user), and if so, this email should be assigned/linked to a certain team. If have already tried to find a way to get this working via formula for Email entity like this:

    ifThenElse(entity\isNew() && >>from condition here<< , entity\addLinkMultipleId('teams', 'my-team-ID'))

    The team assignment works fine in principle (tested with "from == >specific emailAddress<"), but I did not manage to set up a working >from condition<, which should be TRUE if 'from' (senders email) is found in the email addresses of ANY account or contact or lead or opportunity.
    As Espo already links the name of the sender in the email's from field to corresponding contacts or users, I think this should be possible? Would this work using entity formula or do I need the Advanced Pack extension to set up a workflow? Can you help or give advice?


  • #2
    The main code is here
    application/Espo/Core/Mail/Importer.php method importMessage
    it calls from application/Espo/Services/InboundEmail.php

    possible you need to check parent field (parentType and parentId)


    • #3
      Thanks for this, Tanya!

      This is what I found out after some more investigation:
      - Entity formula works fine if I use 'parentType !== null' instead of 'parentType != null' in the formula -- the comparison with '!=' (see documentation) doesn't seem to work correctly. So, what I use now is this:
      ifThen(entity\isNew() && parentType !== null, entity\addLinkMultipleId('teams', 'my-team-ID'))
      - I found that detection of a parent contact does not work (function findParent in application/Espo/Core/Mail/Importer.php). Detection of leads or accounts work fine. Unfortunately, at first I always tested only with contacts and always wondered why it didn't work. Once I tested with leads it worked seamlessly. I stepped into the code and think in function findParent the check for b2c mode should not be negated to work correctly? So it should be like this
      if ($this->getConfig()->get('b2cMode')) {
      instead of
      if (!$this->getConfig()->get('b2cMode')) {
      ? Or am I missing something?

      My Espo works in standard B2B mode (B2C not checked in settings). If I do the above change in code, everything works fine including contacts. Could you please confirm if the current code is correct or not?
      Thanks again!


      • #4
        I've read the code ''' if (!$this->getConfig()->get('b2cMode')) {///} ''' everything is logically. If we found a contact and model is B2B, set as an email parent - the main account of this contact, if B2C - set as an email parent found contact
        About first... will be fixed in the next version
        Last edited by tanya; 06-08-2017, 04:07 PM.


        • #5
          I understand. You are right – the code is correct if the goal is to always find a parent account for a contact. So, it might not be a good idea to use 'single' contacts (contacts without related account) in B2B mode like we currently do for a few contacts, because then nothing is found?


          • #6
            Although I would have preferred to leave the original code unchanged, I added an else clause as a workaround for this to meet our needs...
            If in B2B mode a related account is found for a contact => the related account gets parent. If not => the contact itself gets parent (just like it was, if we were in B2C mode):
            PHP Code:
            if (!$this->getConfig()->get('b2cMode')) {
                if (
            $contact->get('accountId')) {
                } else {


            • #7
              Create own Importer, extends \Espo\Core\Mail\Importer, but override findParent method
              You can customize InboundEmail service (, override the method fetchFromMailServer. Copy core code of this method, but set own importer. Rebuild EcpoCRM