Displaying Full Addresses in Custom Fields

Displaying Full Addresses in Custom Fields

Overview

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 article 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

Here’s a quick look at some common issues you might run into.


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

Some of the best practices are:


  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.




    • Related Articles

    • Creating and Managing Custom Fields

      Overview Custom fields in iVendNext let you tailor forms to fit your specific data needs—like extra customer info, project tags, or inventory tweaks. They help your system match your workflow, not the other way around. This guide walks you through ...
    • Automating Date Fields with Scripts

      Overview 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 business ...
    • Creating and Managing Custom Reports

      Overview This article will guide you through the process of creating and managing custom reports in iVendNext. Why Create Custom Reports? Custom reports in iVendNext allow businesses to extract specific data points and analyze them in a way that ...
    • Editing Fields After Submission and Changing Data Types

      Overview Efficient data entry and clear document identification are critical for productivity in iVendNext. This guide covers two powerful features: Setting default values to automate repetitive inputs. Creating multi-field document titles for better ...
    • Creating Custom Reports Using Report Builder

      Overview Report Builder in iVendNext lets you create custom reports easily—no technical skills needed. From sales summaries to inventory updates, it helps you pull and format data quickly. This article guides you through building a report, choosing ...