Displaying Full Addresses in Custom Fields

Displaying Full Addresses in Custom Fields

Introduction

In iVendNext, addresses are often stored as linked records (e.g., Customer Address), but transactional documents (e.g., Sales Invoices) may only display a truncated reference. This guide explains how to fetch and display complete addresses in custom fields, improving clarity for users and reducing manual lookups.




Why Display Full Addresses?

  • Eliminate Confusion: Show complete details (street, city, ZIP) instead of just "Address-001".

  • Streamline Workflows: Avoid opening linked records to verify addresses.

  • Enhance Reports: Export documents with full address visibility.




Step 1: Add Custom Fields to Your DocType

1. Create a Link Field

  • Purpose: To select an address from the Address master.

  • Setup:

    1. Navigate to:


Setup > Customize > Customize Form  


  1. Select your target DocType (e.g., Sales Invoice).

  2. Add a Link Field:

    • Label: "Address Link".

    • Fieldname: address_link (note this for scripting).

    • Options: "Address" (as the linked DocType).


2. Add a Read-Only Text Field

  • Purpose: To display the full address.

  • Setup:

  • Label: "Full Address".

  • Fieldname: full_address (note this for scripting).

  • Fieldtype: "Text" or "Read Only".




Step 2: Add a Client Script to Fetch the Address

Script Example

ivendnext.ui.form.on("Sales Invoice", "address_link", function(frm) {  

  if (frm.doc.address_link) {  

    // Fetch address from the master  

    frm.call({  

      method: "ivendnexterp.contacts.doctype.address.address.get_address_display",  

      args: { "address_dict": frm.doc.address_link },  

      callback: function(r) {  

        if (r.message) {  

          frm.set_value("full_address", r.message); // Populate the full address  

        }  

      }  

    });  

  } else {  

    frm.set_value("full_address", ""); // Clear if no address selected  

  }  

});  

Key Adjustments

  • Replace "Sales Invoice" with your DocType name.

  • Ensure address_link and full_address match your fieldnames.




Step 3: Test the Implementation

  1. Save & Enable the Script:

    • Go to Custom Scripts, save, and check "Enabled".

  2. Verify in Your Document:

    • Select an address in the address_link field.

    • The full_address field should auto-populate with the complete details.




Advanced Customizations

1. Formatting the Address

Modify the script to customize the address layout (e.g., add line breaks):


callback: function(r) {  

  if (r.message) {  

    const formattedAddress = r.message.replace(/, /g, ",\n");  

    frm.set_value("full_address", formattedAddress);  

  }  

}  


2. Auto-Fetch Based on Customer

If your document has a Customer Link Field, fetch their default address:


ivendnext.ui.form.on("Sales Invoice", "customer", function(frm) {  

  if (frm.doc.customer) {  

    frm.set_value("address_link", frm.doc.customer_primary_address); // Assumes field exists  

  }  

});  




Troubleshooting

Issue

Solution

Address not displaying

Check if the script is enabled and fieldnames match.

Permission errors

Ensure users have read access to the Address DocType.

Broken formatting

Verify the get_address_display method returns data.




Best Practices

  1. Standardize Fieldnames: Use consistent names like address_link across DocTypes.

  2. Combine with Other Scripts: Trigger address updates when a Customer is selected.

  3. Document Dependencies: Note which fields/scripts interact with addresses.




Conclusion

Displaying full addresses in custom fields enhances usability and reduces manual work in iVendNext. By leveraging Link Fields and Client Scripts, you can ensure accurate, readable address data across transactions.




Key Takeaways


✅ Use a Link Field to select addresses and a Read-Only Field to display them.
✅ The get_address_display method fetches formatted addresses.
✅ Test scripts with real data to ensure compatibility.




    • Related Articles

    • Creating and Managing Custom Fields

      Introduction Custom fields allow businesses to extend standard forms in iVendNext to capture unique data requirements. Whether you need to track additional customer details, add project-specific fields, or customize inventory attributes, creating ...
    • Automating Date Fields with Scripts

      Introduction Manually calculating and entering dates in iVendNext documents is error-prone and time-consuming. With custom scripts, you can automate date fields to: ✔ Auto-set deadlines (e.g., Production Due = Delivery Date - 2 days). ✔ Enforce ...
    • Understanding Frozen Fields in the Item Master

      Overview In iVendNext, the Item master is a central component of inventory management, allowing you to define and manage all the items in your inventory. However, certain fields in the Item master become frozen once specific conditions are met. This ...
    • Editing Fields After Submission and Changing Data Types

      Introduction In iVendNext, documents typically lock fields after submission to maintain data integrity. However, businesses often need flexibility—such as updating a "Supplier ID" post-approval or correcting a field with the wrong data type. This ...
    • Creating and Managing Custom Reports

      Introduction In today’s data-driven business environment, having access to accurate and insightful reports is crucial for making informed decisions. iVendNext offers robust reporting capabilities, allowing businesses to create and manage custom ...