Announcement

Collapse
No announcement yet.

Create Lead for Case from Email

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

  • Create Lead for Case from Email

    When the system receives an email, a case automatically created. But if the email address is not in the system, I want to create a lead with the details from the email (sender first/last name, email address).
    I am trying the workflow but no luck.

    Any help would be appreciated.

  • #2
    Hi,
    Maybe you'll find something useful here:
    Hi, It has been some weeks since we are testing a way to create and assign a contact when an email to case is used. We are using EspoCRM as our ticket

    I am new to CRM, not only to EspoCrm, so maybe this is a stupid question. If someone fills in the contactform on our site, this form is emailed to our

    Comment


    • #3
      Originally posted by roma View Post
      Hi,
      Maybe you'll find something useful here:
      Hi, It has been some weeks since we are testing a way to create and assign a contact when an email to case is used. We are using EspoCRM as our ticket

      I am new to CRM, not only to EspoCrm, so maybe this is a stupid question. If someone fills in the contactform on our site, this form is emailed to our

      https://github.com/espocrm/documenta...pment/hooks.md
      Thanks but I already seen those. Those threads have no information regarding my questions, already checked those things. The documentation is very very poor so we are unable to figure out which fields to use, how to debug it etc.

      Any help would be appreciated.

      Comment


      • #4
        1. You need to create formula function that will check if lead exists.

        1.1. Create a file: custom/Espo/Custom/Core/Formula/Functions/MyCustomGroup/RecordExistsType.php

        PHP Code:
        <?php

        namespace Espo\Custom\Core\Formula\Functions\MyCustomGroup;

        use 
        \Espo\Core\Exceptions\Error;

        class 
        RecordExistsType extends \Espo\Core\Formula\Functions\Base
        {
            protected function 
        init()
            {
                
        $this->addDependency('entityManager');
            }

            public function 
        process(\StdClass $item)
            {
                if (!
        property_exists($item'value')) {
                    throw new 
        Error();
                }

                if (!
        is_array($item->value)) {
                    throw new 
        Error();
                }

                if (
        count($item->value) < 3) {
                    throw new 
        Error();
                }

                
        $entityType $this->evaluate($item->value[0]);

                
        $whereClause = [];

                
        $i 1;
                while (
        $i count($item->value) - 1) {
                    
        $key $this->evaluate($item->value[$i]);
                    
        $value $this->evaluate($item->value[$i 1]);
                    
        $whereClause[$key] = $value;
                    
        $i $i 2;
                }

                return !!
        $this->getInjection('entityManager')->getRepository($entityType)->where($whereClause)->findOne();
            }
        }


        1.2 Create a file custom/Espo/Custom/Resources/metadata/app/formula.json

        Code:
        {
            "functionList": [
                "__APPEND__",
                {
                    "name": "myCustom\\recordExists",
                    "insertText": "myCustom\\recordExists(ENTITY_TYPE, ATTRIBUTE, VALUE)"
                }
            ],
            "functionClassNameMap": {
                "myCustom\\recordExists": "\\Espo\\Custom\\Core\\Formula\\Functions\\MyCustomGroup\\RecordExistsType"
            }
        }


        1.3. Clear Cache at Administration.


        2. Create a workflow rule for Email entity type with trigger After Record Created.

        Click image for larger version  Name:	1.png Views:	1 Size:	44.1 KB ID:	45052

        Condition Formula:

        Code:
        string\contains(targetEntity\attribute('to'), 'EMAIL_ADDRESS_OF_YOUR_EMAIL_ACCOUNT')
        &&
        !myCustom\recordExists(
            'Lead',
            'emailAddress',
            targetEntity\attribute('fromAddress')
        )

        Comment

        Working...
        X