Announcement

Collapse
No announcement yet.

Import US format address to Espo format address

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

  • Russ
    replied
    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

    Leave a comment:


  • item
    commented on 's reply
    Haaa just see : more simple in formula



    string\split ","

    then



    array\at

    then as i don't find regex in formula :

    string\split. " "

  • item
    replied
    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

    Leave a comment:


  • Russ
    replied
    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?

    Leave a comment:


  • yuri
    replied
    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.

    Leave a comment:


  • Russ
    started a topic Import US format address to Espo format address

    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!
Working...
X