Announcement

Collapse
No announcement yet.

Import US format address to Espo format address

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

  • 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!

  • #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.

    Comment


    • #3
      Originally posted by yuri View Post
      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


      • #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

        Comment


      • #5
        Originally posted by item View Post
        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...
        X