How to use frappe.db.get_value in Print Format

Hi everyone !

I’m new here and need some help from you guys. I currently develop some custom print formats for Payment Entry. I want to fetch some data from another document. I found that it is compulsory to use “frappe.db.get_value(”[doctype]“, “[name]”, “fieldname”)” in order to get value from another document. I know [doctype] and [fieldname] part but for the [name] part, I have no idea at all. Can someone enlighten me on how to use this scripting :man_mechanic:?



“[name]” part is the filter that you want to fetch your desired fieldname upon, it is equivalent to the what came after where clause in the ordinary SQL query, for example “SELECT posting_date FROM tabPayment Entry WHERE name = ‘PE0001’”; so in the form of frappe.db.get_value it will be:
frappe.db.get_value(”Payment Entry", “PE0001”, “posting_date”)

hope that helps

1 Like

Hi @ahmed-madi :slight_smile:

Thank you so much for your response ! I really appreciate it. However, I got one more question and really hope if you could help me on this.

I currently develop on custom print format for Payment Entry. As far as I know, Payment Entry somehow is connected with Sales Invoice. So let say, in the Payment Entry, I would like to have the party address which only can be retrieved from the Sales Invoice. How can I fetch the data ? Would you mind to explain on this?

Thank you in advance :grinning:

Sales Invoice reference is there inside the child table of the Payment Entry and there can be multiple Invoices. So, first you have to get the Sales Invoice from there. Then you can fetch the address from the sales invoice using frappe.db.get_value

Hi @nabinhait,

Would you mind to explain more on child table part ? Thank you :slight_smile:

I think you can get the invoice_no from the first row using doc.get("items")[0].reference_name

1 Like

hello @ahmed-madi
frappe.db.get_value(”Payment Entry", “PE0001”, “posting_date”)
In the above query instead of name(PE0001) can i use party_name(like:NAGESH V RAO).

Yeah sure you can use it like frappe.get_value("Payment Entry", {"party":"NAGESH V RAO"}, "posting_date") but this will return single value, use this in case to retrieve all matching values in a list frappe.get_list("Payment Entry", {"party":"NAGESH V RAO"}, "posting_date")

1 Like

hiii @ahmed-madi
Yeah its working fine now… thanks for your reply giving me a suggestion…

Thanks & Regards
Mohammad Eliyas:blush:

can anyone check my post here

in pdf, frappe.get_value, cannot display.

Is there any solution?

try assigning it to a variable first.
{% set tax_id = frappe.db.get_value(“Customer”, doc.customer, “tax_id”) %}
{% set customer_code = frappe.db.get_value(“Customer”, doc.customer, “customer_code”) %}

TRN # {{ tax_id }}
Customer#: {{ customer_code }}

1 Like

Do you know of a way to use a match(=) instead of a specific name?
For example if you wanted to use get_value where field1 in doctype A = field 1 in doctype B

Use the frappe.db.sql() method and insert into it a normal join query string between both tables as a parameter like:

       frappe.db.sql(""" select,cc.from_date,cc.to_date,ca.amount,ca.currency
	from `tabCertified Consultant` cc
	inner join `tabCertification Application` ca
	on cc.certification_application =
	where paid = 1 and email = %(user)s order by cc.to_date desc""" ,{'user': frappe.session.user},as_dict=True)