Fetch the entire address text on a custom field
Fetch the entire address text on a custom field
This article will walk you through a three-step process for adding a custom field that will retrieve full addresses for any DocType.
Step 1. Cosmetic customisations on the required DocType
To obtain addresses, we would first need to add two new fields to the DocType:
a) A "Link" field that refers to our Address master
b) A "Read Only" box that would show the complete address
Note the names of the variables you use to create the new fields. Later in the procedure, this data will be needed.
You can click on the following link, Custom Fields in ERPNext, for details on how to add custom fields to a DocType.
After completing this step, the chosen DocType should have two new fields, as shown below:-
Step 2. Adding a Client Script for fetching the full address from our Address master
Create a new Client Script by typing "Client Script" into the search field. Choose the necessary DocType from which to obtain the address.
Paste the following client script into the script section:-
Depending on your use case, we will need to replace the following adjustments here:
A) Change "DocType Name" to the name of the document type on which we need to retrieve the address. Such as a sales invoice or purchase order.
b) Substitute the variable name for the unique link field we defined in Step 1 for "address link field."
c) Substitute the variable name for the unique read-only field we defined in Step 1 for "full address field."
After doing this, you will have a client script that looks like the following:
Step 3. Save, enable and test the Client Script
When the Client Script has been modified to suit your needs, we can save it and turn it on by checking the "Enabled" box.
For the modifications to take effect, visit the necessary DocType and reload the page.
Now, the complete address will be fetched on our custom read-only field when an address is selected on our custom link field, as shown below: