Autofill postcode and district after choosing street

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tziere
    Member
    • Jul 2020
    • 42

    Autofill postcode and district after choosing street

    Hi!

    Currently I have an address entity with (street)name, postcode and district fields. This entity is linked one-to-many to contacts.
    I was wondering if it is possible to autofill postcode and district fields after a street is selected for a contact.


  • Maximus
    Senior Member
    • Nov 2018
    • 2731

    #2
    Hi there,
    Yes, you can define Formula for such things, so after you fire the save button the required data will be auto-populated.
    Please read more about formula here https://docs.espocrm.com/administration/formula/.

    Comment

    • Tziere
      Member
      • Jul 2020
      • 42

      #3
      Hi Maximus,

      Thanks for your reply! I looked into this, but I could not really find out how to do it.
      Could you maybe point me in the right direction?

      Kind Regards

      Comment

      • Tziere
        Member
        • Jul 2020
        • 42

        #4
        Figured it out, thanks!
        Used following formula: autoPC = adressLink.postalcode;

        Comment

        • Maximus
          Senior Member
          • Nov 2018
          • 2731

          #5
          Ok, let's imagine that your address entity called Address, and you use the same address type filed for it as the Contact entity does.

          Open Administration -> Entity Manager -> Contact -> Formula:
          Code:
          ifThenElse(
              entity\isAttributeChanged('basicId') && basicId,
          
              addressCity = address.addressCity;
              addressState = address.addressState;
              addressStreet = address.addressStreet;
              addressCountry = address.addressCountry;
              addressPostalCode = address.addressPostalCode,
          
              addressCity = null;
              addressState = null;
              addressStreet = null;
              addressCountry = null;
              addressPostalCode = null
          );
          This formula will check whether you change the link Address field and whether there is some selected Address. If True, then it will populate those elements. If False, then it will rewrite the Contact address to blank.

          Comment

          • emillod
            Active Community Member
            • Apr 2017
            • 1405

            #6
            I think that better approach is creating custom hook which will run every time when someone change address field.
            If someone change that field, hook will take street name and check postalcode in local library. After hook will find match for street and district, script in hook can change zip code field.

            I tried to find something fast and maybe this package of composer let you search zip code based on street and district: https://packagist.org/packages/commerceguys/addressing

            Please let me know if you have any questions. I have similar issue, i had to create for my espocrm client a mechanism which will find country based on phone number

            Comment

            Working...