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.
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.
Purpose: To select an address from the Address master.
Setup:
Navigate to:
Setup > Customize > Customize Form
Select your target DocType (e.g., Sales Invoice).
Add a Link Field:
Label: "Address Link".
Fieldname: address_link (note this for scripting).
Options: "Address" (as the linked DocType).
Purpose: To display the full address.
Setup:
Label: "Full Address".
Fieldname: full_address (note this for scripting).
Fieldtype: "Text" or "Read Only".
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
}
});
Replace "Sales Invoice" with your DocType name.
Ensure address_link and full_address match your fieldnames.
Save & Enable the Script:
Go to Custom Scripts, save, and check "Enabled".
Verify in Your Document:
Select an address in the address_link field.
The full_address field should auto-populate with the complete details.
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);
}
}
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
}
});
Here’s a quick look at some common issues you might run into.
Some of the best practices are:
Standardize Fieldnames: Use consistent names like address_link across DocTypes.
Combine with Other Scripts: Trigger address updates when a Customer is selected.
Document Dependencies: Note which fields/scripts interact with addresses.