ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Data Fetch Using Jinja Template


#1

Hi,
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 ‘’ }}


#2

Please Help!


#3

{% 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 ‘’" }}


#4

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)

%}
{{ u2.name }}

Thanks


#5

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


#6

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

but I am getting below errojinja


#7

this will work:

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

{{ u2.name }}

#8

@Mohammed_Redha
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”, u2.name) %}
{{u1.lead_name}}
{{u2.entity_name}}
{{u3.name}}

Thanks


#9

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

where are you filtering “entity_name”?


#10

@Mohammed_Redha

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


#11

@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":"test@example.com"})

#12

@Mohammed_Redha

but i am using jinja template to get data.


#13

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


#14

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


#15

@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”, u2.name) %}
{{u1.lead_name}}
{{u2.entity_name}}
{{u3.name}}


#16

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


#17

pls use this

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


#18

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


#19

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

this should work now :slight_smile:


#20

{% 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’:u2.name},‘name’) %}
{{age_group}}

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.