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 ?
“[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”)
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?
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
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")
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.name,cc.from_date,cc.to_date,ca.amount,ca.currency
from `tabCertified Consultant` cc
inner join `tabCertification Application` ca
on cc.certification_application = ca.name
where paid = 1 and email = %(user)s order by cc.to_date desc""" ,{'user': frappe.session.user},as_dict=True)