How to get changes value from one doctype to another doctype . Example

One doctype is connected to another doctype then even if I change anything in the first doctype, it is not automatically changed in the other doctype. How to solve ?

Hi @kirankumari

Write a function on_update of first doctype.

In the function get the second doctype and update from the code.

1 Like

@Usama_Naveed is rights, you have to use the on_update or after_save(if you use the server script doctype) doc_events.

To automatically update a field in one doctype when a related doctype is changed, you can use a server script. This script runs whenever you update the first doctype, and it finds and updates the related records in the second doctype.

Example:

def update_linked_doc_type(doc, method):
    linked_docs = frappe.get_all('DocType B', filters={'doc_a_link': doc.name})
    
    for linked_doc in linked_docs:
        b_doc = frappe.get_doc('DocType B', linked_doc.name)
        b_doc.field_b = doc.field_a
        b_doc.save()

This script makes sure that when a field in DocType A changes, the corresponding field in DocType B is automatically updated.

3 Likes

this is my doc_events
doc_events = {
“CG User”: {
“on_update”: “…/api/onUpdate.py/update_linked_doc_type”
}
}
And i am getting this error message
App …/api/onUpdate is not installed

@kirankumari you can not add path like this check this Need Help on Document Event Hooks for Standard DocTypes

not use /, use dot

example:

doc_events = {
	"Account": {
		"on_update": "dev_test_frappe.doc_event.account.account_number",
	}
}
3 Likes