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

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

Overview

Avoid manual data entry in iVendNext.

Instead of copying details between documents, use field mapping and scripts to auto-fill data accurately. This guide shows you how.


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

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


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

Here’s a quick look at some of the best practices for fetching data across documents.


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




    • Related Articles

    • Fetching Data from Linked Masters

      Overview 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 article explains how to auto-fetch information from ...
    • Working with Query Reports - Fetching Data Directly from the Database

      Overview Query Reports in iVendNext let advanced users pull data using SQL for detailed, custom reporting. Unlike the no-code Report Builder, they offer full control over data queries—ideal for complex needs. However, cloud users can't write SQL ...
    • Step-by-Step Guide to Creating an Auto Lookup Profile

      Overview This article walks you through creating and optimizing an Auto Lookup Profile, complete with visual aids and expert tips. Before You Begin: Key Concepts Let’s look at the key concepts: What is an Auto Lookup Profile? An intelligent ...
    • User Permissions: Restricting Access to Specific Documents

      Overview Role-Based Permissions manage access to document types, while User Permissions limit access to specific records like assigned customers or territories. This guide shows how to set up User Permissions for tighter data control. 1. When to Use ...
    • Unreserving Stock in iVendNext: A Step-by-Step Guide

      Overview This guide will walk you through the process of unreserving stock in iVendNext. You must ensure that your stock balance is positive before you enable the “Stock Reservation” feature. When you enable the “Stock Reservation” feature additional ...