Fetching Data from Linked Masters

Fetching Data from Linked Masters

Introduction

In iVendNext, linked masters (e.g., Customers, Items, Contracts) store centralized data that multiple documents reference. Manually re-entering this data wastes time and risks errors. This guide explains how to auto-fetch information from linked masters into your transactions using field mapping, scripts, and best practices.




When to Use Linked Data Fetching

Automate data transfer for:
Customer/Vendor Details (e.g., VAT ID, Payment Terms).
Product Information (e.g., Description, UOM).
Standardized Templates (e.g., Terms & Conditions).




Method 1: Field Name Matching

How It Works

If a Link Field (e.g., customer) points to a master, and both documents share fields with the same name, iVendNext auto-populates the data.


Step-by-Step Setup

  1. Add Matching Fields:


  • In your document (e.g., Sales Invoice), add fields with names identical to the master (e.g., vat_id).


  1. Create the Link:


  • Ensure your document has a Link Field (e.g., customer) pointing to the master (e.g., Customer).


  1. Test:


  • Select a Customer → vat_id auto-fills.


Note:


  • Field names must match exactly (e.g., vat_idvat_number).

  • Works for Text, Date, Check, and Number fields.




Method 2: Using add_fetch for Non-Matching Fields

When to Use

If field names differ between documents (e.g., master uses tax_id, but your form uses vat_number), use the add_fetch method.


Script Example

// In Sales Invoice Custom Script  

cur_frm.add_fetch('customer', 'tax_id', 'vat_number');  


  • customer: Link Field in your document.

  • tax_id: Source field in the Customer master.

  • vat_number: Target field in your document.


InfoResult: Selecting a Customer auto-populates vat_number from their tax_id.




Method 3: Fetching Full Addresses

Step-by-Step

  1. Add Fields to Your DocType:


  • A Link Field (address_link) pointing to Address.

  • A Read-Only Text Field (full_address).


  1. Add a Client Script:


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

  if (frm.doc.address_link) {  

    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);  

      }  

    });  

  }  

});  


  1. Test:


  • Select an address → full_address displays the complete text.




Method 4: Pulling Terms & Conditions

Scenario

Auto-fetch pre-approved terms from a Contract Template into a Sales Order.


Setup

  1. Add Fields:


  • A Link Field (contract_template) pointing to Contract.

  • A Read-Only Text Editor (terms).


  1. Configure "Fetch From":


  • In terms field properties, set:


contract_template.terms  


  1. Test:


  • Select a Contract Template → terms auto-populates.




Troubleshooting

Issue

Solution

Data not fetching

Verify field names match exactly (case-sensitive).

Script errors

Check browser console for typos in method names.

Blank values

Ensure the master document has data in the source field.




Best Practices

  1. Standardize Field Names: Use consistent names (e.g., vat_id across all docs).

  2. Document Dependencies: Note which fields rely on linked masters.

  3. Validate Permissions: Ensure users can read the master data.




Conclusion

Fetching data from linked masters eliminates manual entry and ensures consistency across documents. Whether using field matching, add_fetch, or custom scripts, automate workflows to save time and reduce errors.




Key Takeaways


✅ Field matching works for identical field names.
✅ Use add_fetch to map differently named fields.
✅ Client scripts fetch complex data (e.g., addresses).




    • Related Articles

    • Customizing Data Flow with Linked Masters

      Overview Mastering data relationships is key to building efficient business systems. iVendNext's Linked Masters feature enables intelligent data flow between connected documents, eliminating redundant data entry while maintaining data integrity. This ...
    • Fetching Data Across Documents - A Step-by-Step Guide

      Introduction In iVendNext, manually re-entering data across linked documents (e.g., copying Customer PO details from a Sales Order to a Sales Invoice) is time-consuming and error-prone. This guide explains how to automatically fetch data between ...
    • Working with Query Reports - Fetching Data Directly from the Database

      Introduction Query Reports in iVendNext allow advanced users to extract data directly from the database using SQL (Structured Query Language). Unlike Report Builder, which offers a no-code interface, Query Reports provide granular control over data ...
    • Fetching Data from Child Tables Using Jinja Tags

      Introduction Child tables in iVendNext (e.g., Items, Taxes, or Additional Costs) store multi-row data linked to a parent document (e.g., Sales Invoice or Purchase Order). While Report Builder displays child table rows as duplicate lines, Jinja ...
    • Common Party Accounting: Managing Transactions with Linked Parties

      Overview In some business scenarios, a single party may act as both a customer and a supplier. For example, a company might purchase raw materials from a supplier and also sell finished goods back to the same party. iVendNext’s Common Party ...