How to get values from other DocType with conditions

Hello,

Anyone please guide me how can I display a contact designation on Quotation Document?
I tried to use something like this
{{ frappe.db.get_value("Contact", { "..........": doc.contact_display }, "designation") or "" }}

But the contact_display, the quotation field, shows as a full name whereas there is no full name field in DocType “Contact” except first_name and last_name.

Please help and thanks so much in advance.

Regards,

Why Jinja?
Check add_fetch method.
https://erpnext.org/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/custom-script-fetch-values-from-master

Hello and thanks so much for your reply.

cur_frm.add_fetch(‘customer’,‘vat_id’,‘vat_id’)
Is it possible to declare and use for the second parameter? As I described, the field ‘Contact_display’ that shows a full name in Quotation DocType doesn’t match to the field in Contact DocType that comprise ‘first_name’ and ‘last_name’.

I’d like to code like this below :
cur_frm.add_fetch(‘contact’,‘first_name+last_name’,doc.contact_display)

Something like this. Please help me to revise the above code.

Thanks
Regards,

For that, you need to set the field value using custom logic.

frappe.db.get_value('Contact', {name: 'contact_name'}, 'first_name')
	.then(r => {
		const first_name = r.message.first_name;

		frappe.db.get_value('Contact', {name: 'contact_name'}, 'last_name')
			.then(r => {
				const last_name = r.message.last_name;

				const full_name = first_name + ' ' + last_name;

				cur_frm.set_value('contact_display', full_name)
			})
	})
2 Likes

Are there any dev docs about that?

1 Like