Email to Case for Contacts Only

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marcbeinder
    Member
    • May 2018
    • 68

    Email to Case for Contacts Only

    Is it possible to restrict the email to case feature to only create a case for contacts that already exist in the system.

    For example:
    John Smith is a contact with email john@smith.com. John uses this address to email support@example.com. A case is created.

    Jane Doe is not a contact and has no emails in the system. Jane sends an email to support@example.com. A case is not created.

    Is this functionality possible?
  • item
    Active Community Member
    • Mar 2017
    • 1476

    #2
    Hi,

    here you have the function but I don’t know if you can have in upgrade save

    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment

    • marcbeinder
      Member
      • May 2018
      • 68

      #3
      Thank you for this. I’ll review the code and post any questions I have here in this thread.

      Comment

      • marcbeinder
        Member
        • May 2018
        • 68

        #4
        From reading this code, it appears that if a contact cannot be located, then the system falls back to the account and looks for a lead with that email address. If no lead is found, it just creates the case with no contact/lead records. Am I reading this correctly? Is there a way to add a checkbox to a Group Email Account to enforce this rule? If someone could show me how to create such an option, I'd be happy to PR it as time allows.

        Comment

        • item
          Active Community Member
          • Mar 2017
          • 1476

          #5
          Hi,
          in the past i have searched for something like your request, and in many place "Account, Contact, Lead" it's hard coded.
          i am not a "good developper" .. but i think it's the way.

          All below is sample, you can adapt name or ..

          1) create a multi-enum Field : createCaseForEntity : ["Account", "Contact", "Lead"] like caseDistribution

          https://github.com/espocrm/espocrm/b...mail.json#L135

          2) make it visible on the layout, just like caseDistribution

          https://github.com/espocrm/espocrm/b...etail.json#L51

          3) adapt view detail in some place like

          https://github.com/espocrm/espocrm/b...detail.js#L182

          At this moment, if you can see the new field/hide/show and save correctly in database it's good i think

          Now we need to adapt the function :

          https://github.com/espocrm/espocrm/b...Fetch.php#L581

          PHP Code:
          <?php
             if (!empty($params['createCaseForEntity'])) {   $createCaseForEntity = $params['createCaseForEntity'];   }   // multi-enum, certainly need to cast in array..
          
          // and the logic for all
          
          foreach( $createCaseForEntity as $entityType ){  
             $foundEntity = $this->entityManager->getRDBRepository( $entityType )   ->join('emailAddresses', 'emailAddressesMultiple')   ->where([   'emailAddressesMultiple.id' => $email->get('fromEmailAddressId'),   ])   ->findOne();      
          
            if ($foundEntity) {  
               $case->set( lowerCase( $entityType ).'Id'  , $foundEntity->getId());  
                ​
               $this->entityManager->saveEntity($case);
               $email->set('parentType', CaseObj::ENTITY_TYPE);   $email->set('parentId', $case->getId());
            }  }
          
          Maybe.


          edit : maybe need order entityType, so if first if find, break the loop.. need add custom person entity in this..
          Last edited by item; 11-28-2022, 12:51 AM.
          If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

          Comment

          • marcbeinder
            Member
            • May 2018
            • 68

            #6
            Thank you! I will research this in the morning and see what I can come up with. If I can get this to work as expected and within the code standards, I'll submit a PR.

            Comment

            • item
              Active Community Member
              • Mar 2017
              • 1476

              #7
              Hi,
              i have tested, point 1, 2, 3 .. it's ok .. i have field and save in database.
              maybe, we can do 1, 2, 3 upgrade save. .. certainly.

              after problem begin (my skill) .. how use/override the function "createCase".

              Then one more think : feature request :

              we have, account, person, event, ... why not have a entity template "Case" ...
              so imagine :
              support@xyz => create "Case like Support entity"
              info@xyz => create "Case like Info entity"

              So in GroupEmailAccount, we need select witch EntityType .. and For witch related (not only contact or lead, but other custom entity)

              it's doable for me
              If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

              Comment

              Working...