Import US format address to Espo format address

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Russ
    Senior Member
    • Feb 2022
    • 423

    Import US format address to Espo format address

    How can we import files with such address:
    10749 New Haven St UNIT 1, Sun Valley, CA 91352

    To Espo formatted address, and make it
    Street: 10749 New Haven St UNIT 1
    City :Sun Valley
    State: CA
    Postal: 91352

    I know that system can do a very similar thing to the name, parse it, and make it first/last, but I can't find anything similar for the address, any options?

    I appreciate your help!
  • yuri
    Member
    • Mar 2014
    • 8453

    #2
    There's no such ability. One possible solution is to create a custom auxiliary field (of varchar or text type) and write a parsing formula script or a custom formula function. Import the address to this field, the formula will parse it and set parsed values to address fields.
    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

    • Russ
      Senior Member
      • Feb 2022
      • 423

      #3
      Originally posted by yuri
      There's no such ability. One possible solution is to create a custom auxiliary field (of varchar or text type) and write a parsing formula script or a custom formula function. Import the address to this field, the formula will parse it and set parsed values to address fields.
      Thanks!
      Very interesting, can you please help with such formula?

      Comment

      • item
        Active Community Member
        • Mar 2017
        • 1476

        #4
        Hi,
        it's not formula but something so :

        with this sample : 10749 New Haven St UNIT 1, Sun Valley, CA 91352


        PHP Code:
        <?php
        namespace Espo\Custom\Hooks\Lead;
        
        use Espo\ORM\Entity;
        
        class MyHook
        {    
            // An optional parameter, defines in which order hooks will be processed.
            // Lesser value means sooner.
            public static $order = 5;
        
            public function __construct(
                // Define needed dependencies.
            ) {}
        
            public function beforeSave(Entity $entity, array $options): void
            {
                if ($entity->isNew() && $entity->get('flatAddressField')) {
                    $addressArray = explode(",", $entity->get('flatAddressField'));
        
                    $entity->set('addressStreet', $addressArray[0]);
                    $entity->set('addressCity', $addressArray[1]);
                    $entity->set('addressState', preg_replace( '/[^a-z]/i', '',  $addressArray[2]));
                    $entity->set('addressCountry', preg_replace( '/[^0-9]/i', '',  $addressArray[2]));
        
                }
            }
        }
        of course, you need to rename/correct some field for your requirement
        If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

        Comment

      • Russ
        Senior Member
        • Feb 2022
        • 423

        #5
        Originally posted by item
        Hi,
        it's not formula but something so :

        with this sample : 10749 New Haven St UNIT 1, Sun Valley, CA 91352


        PHP Code:
        <?php
        namespace Espo\Custom\Hooks\Lead;
        
        use Espo\ORM\Entity;
        
        class MyHook
        {
        // An optional parameter, defines in which order hooks will be processed.
        // Lesser value means sooner.
        public static $order = 5;
        
        public function __construct(
        // Define needed dependencies.
        ) {}
        
        public function beforeSave(Entity $entity, array $options): void
        {
        if ($entity->isNew() && $entity->get('flatAddressField')) {
        $addressArray = explode(",", $entity->get('flatAddressField'));
        
        $entity->set('addressStreet', $addressArray[0]);
        $entity->set('addressCity', $addressArray[1]);
        $entity->set('addressState', preg_replace( '/[^a-z]/i', '', $addressArray[2]));
        $entity->set('addressCountry', preg_replace( '/[^0-9]/i', '', $addressArray[2]));
        
        }
        }
        }
        of course, you need to rename/correct some field for your requirement
        Thanks, I will try

        Comment

        Working...