Fetching Data Across Documents - A Step-by-Step Guide

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 documents using field mapping, scripts, and best practices to ensure accuracy and efficiency.

Idea
You can add Custom Fields using the Customize Form feature in iVendNext.





When to Use Data Fetching

Automate data transfer in these scenarios:


  • Creating Sales Invoices from Sales Orders.

  • Pulling Terms & Conditions from a master document.

  • Syncing customer/vendor details across transactions.




Method 1: Field Name Matching

How It Works

If two documents have fields with the exact same name, iVendNext auto-populates the target field when creating a linked document.


Step-by-Step Setup

  1. Identify Source and Target Fields


  • Example: Fetch po_number from Sales Order to Sales Invoice.


  1. Add Matching Fields (if missing):


  • Go to: Setup > Customize > Customize Form  


  • Add the same field name (po_number) to both documents.


  1. Test the Flow


  • Create a Sales Invoice from a Sales Order.

  • The po_number will auto-populate.


Note:


  • Field names must match exactly (case-sensitive).

  • Works for Text, Date, Link, and Number field types.




Method 2: Using add_fetch for Linked Masters

How It Works

For fields that don’t match names (e.g., fetching a customer’s vat_id), use the add_fetch method in a Custom Script.


Step-by-Step Setup

  1. Add Fields to Both Documents:


  • Add vat_id (Text field) to Customer and Sales Invoice.


  1. Create a Client Script:


// In Sales Invoice Custom Script  

cur_frm.add_fetch('customer', 'vat_id', 'vat_id');  


  • customer: Link field in Sales Invoice.

  • vat_id: Source field (Customer).

  • vat_id: Target field (Sales Invoice).


  1. Save and Test:


  • Select a Customer in the Sales Invoice.

  • The vat_id will auto-fetch.




Method 3: Fetching Full Addresses

How It Works

Display a complete address from a Link Field (e.g., Customer Address) in a read-only field.


Step-by-Step Setup

  1. Add Fields to the 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);  

      }  

    });  

  } else {  

    frm.set_value("full_address", "");  

  }  

});  


  1. Save and Enable the Script:


  • The full_address field will update when an address is selected.




Method 4: Fetching Terms & Conditions

How It Works

Pull pre-defined terms from a master document (e.g., "Contract Templates") into transactions.


Step-by-Step Setup

  1. Add a Link Field (terms_template) to your form.


  1. Add a Read-Only Text Editor Field (terms).


  1. Configure "Fetch From":


  • Set:


terms_template.terms  


  • This maps the terms field from the linked template.


  1. Test:


  • Select a template in the form.

  • Terms auto-populate.




Troubleshooting

Issue

Solution

Data not fetching

Verify field names match exactly.

Script errors

Check console logs for typos in method names.

Permissions

Ensure users have read access to source documents.




Best Practices

  1. Standardize Field Names: Use consistent naming (e.g., po_number everywhere).

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

  3. Test Extensively: Validate with edge cases (e.g., blank fields).




Conclusion

Automating data fetching in iVendNext reduces manual entry, minimizes errors, and speeds up workflows. Whether using field matching, add_fetch, or custom scripts, choose the method that aligns with your document relationships.




Key Takeaways


✅ Field matching works for simple, same-name transfers.
✅ Use add_fetch for linked masters (e.g., customer VAT ID).
✅ Client scripts enable complex fetches (e.g., full addresses).






    • Related Articles

    • 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 ...
    • 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 ...
    • Step-by-Step Guide to Creating an Auto Lookup Profile

      Overview In today's fast-moving retail environment, every second counts at the checkout. iVendNext's Auto Lookup Profile eliminates time-consuming manual searches by automatically retrieving product details, pricing, and customer information. This ...
    • Managing Item Rates Across the Sales Cycle

      Overview In the dynamic world of sales and procurement, it’s not uncommon for the rates of items to fluctuate between the time a Sales Order is created and when the final Sales Invoice is issued. iVendNext offers the flexibility to manage these rate ...
    • User Permissions: Restricting Access to Specific Documents

      Introduction While Role-Based Permissions control access to document types (e.g., Sales Orders, Leave Applications), User Permissions take security further by restricting users to specific records—such as only their assigned customers, territories, ...