Announcement

Collapse
No announcement yet.

Autofill postcode and district after choosing street

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

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



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


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


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

        Comment


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


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