Beginner May 2, 2026 · 1 min read

To pull field data from another DocType using Jinja in a Print Format, you can use the frappe.db.get_value() method. Here’s an example:

Scenario

Let’s say you are working on a Print Format for the Sales Invoice DocType, and you want to display the tax ID of the company associated with the invoice. The Company DocType has a field tax_id.

Jinja Code for the Print Format

<div>
   <strong>Company Tax ID:</strong>
   {{ frappe.db.get_value('Company', doc.company, 'tax_id') or 'N/A' }}
</div>

Explanation

frappe.db.get_value():

Fetches the value of a specific field from another DocType.

In this example:

'Company' is the target DocType.

doc.company is the name (primary key) of the document in the Company DocType. The doc variable represents the current document being printed (in this case, the Sales Invoice).

'tax_id' is the field in the Company DocType whose value you want to display.

or 'N/A':

Ensures that if the tax_id field is empty or null, the text 'N/A' is displayed instead.

Example Output

If the Company associated with the Sales Invoice is ABC Corp and its tax ID is 123456789, the output will be:

<div>
   <strong>Company Tax ID:</strong>
   123456789
</div>

Notes

  • This method works only for single-value fields in the referenced DocType.
  • For child tables or more complex queries, consider using server-side scripts to fetch and process the data before rendering it in the Print Format.
Was this article helpful?