ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Data Fetch Using Jinja Template


I want to Fetch Data from Multple Doctype into sales Invoice Print Format using jinja Template.
Is it Possible ? if possible Please Suggest ASAP.

for refrence.

{% set u = frappe.get_doc(“Risk Profile”, doc.rpd_id) %}
{{ u.age_group or ‘’ }}


Please Help!


{% set u1= frappe.get_doc(“Doctyp 1”, doc.doc_id)
set u2= frappe.get_doc(“Doctyp 2”, doc.doc_id)
set u3= frappe.get_doc(“Doctyp 3”, doc.doc_id)


{{ u1.age_group or ‘’" }} - {{ u2.age_group or ‘’" }} - {{ u3.age_group or ‘’" }}


Hi @Mohammed_Redha Thans for quick reply.
what i actually wanted let see the below example

// it’s filter data from customer
{% set u1= frappe.get_doc(“Customer”, doc.customer)

// i want to fetch Data from Leads (I.E Sales Invoice Connected with Customer but not connected with Leads.
set u2= frappe.get_doc(“Lead”, u1.lead_name)

{{ }}



@hari.kishor I think your code should work fine
what is your problem?


{% set u1= frappe.get_doc(“Customer”, doc.customer)
set u2= frappe.get_doc(“Lead”, u1.lead_name)
{{ }}

but I am getting below errojinja


this will work:

{% set u1= frappe.get_doc("Customer", %}
{% set u2= frappe.get_doc("Lead", u1.lead_name) %}

{{ }}


This is working fine but in another doctype field entity_name is Data field type which is connected with Lead ID.
Is it possible to filter without link type field ?

below Code
{% set u1= frappe.get_doc(“Customer”, doc.customer) %}
{% set u2= frappe.get_doc(“Lead”, u1.lead_name) %}
{% set u3= frappe.get_doc(“Risk Profile”, %}



@hari.kishor yes, you can filter with a data field

where are you filtering “entity_name”?



entity name is the field in Risk Profile doctype.
in that lead_name is stored.
but now when we want Risk Profile details from lead_name it is not coming


@hari.kishor becuse frappe.get_doc will bring only document by primary key .
to make filter with another field you have to use frappe.get_list:

frappe.get_list("ToDo", fields=["name", "description"], filters = {"owner":""})



but i am using jinja template to get data.


@hari.kishor let me ask you something , is it possible “entity_name” value to be in multiple record?


“entity_name” is field in which stored the lead_id, customer_id.


@hari.kishor then “entity_name” is Unique. if so, try this:

{% set u1= frappe.get_doc(“Customer”, doc.customer) %}
{% set u2= frappe.get_list(“Lead”, fields=[“entity_name”], filters = {“entity_name”:u1.lead_name}) [0]%}
{% set u3= frappe.get_doc(“Risk Profile”, %}


@Mohammed_Redha it’s giving below errors
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 65, in get_doc
raise ValueError(’“doctype” is a required key’)
ValueError: “doctype” is a required key


pls use this

{% set parent = frappe.db.get_value(‘Dynamic Link’,{‘company’:doc.comapny},‘parent’)%}


@AkshayJadhao i have used own doctype where not stored the company information.


{% set age_group = frappe.db.get_value(‘Risk Profile’,{‘name’:doc.rpd_id},‘age_group’) %}

this should work now :slight_smile:


{% set u1= frappe.get_doc(“Customer”, doc.customer) %}
{% set u2= frappe.get_doc(“Lead”, u1.lead_name)%}
{% set age_group = frappe.db.get_value(‘Risk Profile’,{‘entity_name’},‘name’) %}

Thanks, that’s working.

one more query :

  1. how can i use sql syntax with jinja?
  2. I have 2 doctypes - 1. Risk Profile and 2. Lead
    Both have common field that is LEAD ID which is store in Risk Profile as entity name
    I want to fetch the email id in Email Alert which is store in Lead Doctype to shoot the email whenever Risk Profile doc is submitted.
    Hope you understood, if any query let me know as this is important for me, your support is highy appreacibale.