Fetch data from another DocType

Hello guys,

I have the following custom doctypes and fields:

Doctype : ,Contracte"
Fields: ,adresa_email_presedinte" and ,adresa_email_administrator"

Doctype: ,Sesizari"
Fields: ,adresa_email_1" and ,adresa_email_2"

Can you please help me to get in doctype ,Sesizari" the values from ,adresa_email_presedinte" to ,adresa_email_1" and ,adresa_email_administrator" to ,adresa_email_2".

Doctype ,Sesizari" is linked to doctype ,Contracte", what I am trying to do is to send an email/notification to those 2 email addresses when a new doc Sesizari is created.

Thanks!

Hello,

Any idea?

Thanks!

Can you translate the doctypeā€™s names to help you better?

Hi @yefritavarez

Doctype : ,Contracte"-contracts
Doctype: ,Sesizari" - issues
Custom field email_address_president
Custom field email_address_administrator

All are custom field and custom doctypes

Please check the following link:
https://erpnext.org/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/custom-script-fetch-values-from-master

Hi,

Still not working, value is not getting.

Can you please help

Thanks!

Any ideea?

Step 1: Create a link filed in Sesizari doc [type: link, Options: Contracts, name: contract]
Step 2:
Also create two email type field email_address_presiden & email_address_administrator (Mark readonly).
On options filed set contract.email_address_presiden & contract.email_address_administrator
Step 3:
Go to Setup > Email Alert > Create an email alert set Email By Document Field email_address_presiden and email_address_administrator

How do I create an Email Field?
If in Options I add also contract.email_address_president the email is showed but in the alert I can not see the field, just seeing owner, nothing else.

@Florea_Andrei Put Email as options and type as code, then via custom script put the field value:

frappe.ui.form.on(ā€œSesizariā€, ā€œcontractā€, function(frm, cdt, cdn){
frappe.call({
ā€œmethodā€: ā€œfrappe.client.getā€,
args: {
doctype: ā€œContractsā€,
name: frm.doc.contract
},
callback: function (data) {
frappe.model.set_value(cdt, cdn, ā€œemail_address_presidenā€, data.message.email_address_presiden);
frappe.model.set_value(cdt, cdn, ā€œemail_address_administratorā€, data.email_address_administrator);
}
})
});

Hi,

Thanks for your help!

I have managed to have this resolved.

Could you kindly share the snippet that helped you solve this issue?
Thanks

1 Like
  1. for get value from another doctype
    value = frappe.db.get_value(ā€™ Contracteā€™,{ā€˜give_any_filed_name_of_ontracteā€™ : ā€˜field_valueā€™}, ā€˜adresa_email_presedinteā€™)
    inside { } we can use filters(field_name and field_values) for find specific doctype what we want. eg: {'name,: ā€˜nameā€™, ā€˜ageā€™:23}
  2. set value to Sesizari which value we are taken from Contracte
    frappe.db.set_value(ā€˜Sesizariā€™,{{ā€˜give_any_filed_name_of_sesizariā€™ : ā€˜field_valueā€™},ā€˜adresa_email_1ā€™)
3 Likes

Thanks a lot.