Try ERPNext Buy Support Partners Foundation

How to update a doctype fields values from another doctype

Hello guys. I have a frappe application with 2 doctypes “property and payment”. I have a select field in property called “status” where the options are “Available” and “Rented”. And i have a link field to the property dcotype in my payment doctype.
I want the “status” field in the Property doctype to change to “Rented” when i create a new record in the Payment doctype linking a paticular property.

how to i go about acheiving this? mind you i am a beginner on frappe framework

try below:

doc = frappe.get_doc(“Property”, docname)
doc.status = “<desire_status>”
doc.save()

In what file do I implement this? And which doctype

Hi,
You can do this on payment doctype, .py file.
On validate event:

def validate(self):
doc = frappe.get_doc(“Property”, docname)
doc.status = “Rented”
doc.save()

You can also use like this
frappe.db.set_value(“Property”, {“name”: doc_name}, “status”, “Rented”)

Hi madu,
There are different purposes of using these methods
To set a single value at a time, you can use
frappe.db.set_value(“Property”, {“name”: doc_name}, “status”, “Rented”)
To set multiple values at a time. you can use

doc = frappe.get_doc(“doctype name”, docname)
doc.status = “xyz”
doc.customer_name = “abc”
doc.amount = 123
doc.save()

thanks for the reply. i tried it but it didnt work

What is the fieldname of your link field on the payment doctype use that fieldname instead of docname.
Self.your_fieldname

i did that but its still not working
payment1

this is a screenshot of my payment Doctype

Try using ‘doc.insert()’ instead of ‘doc.save()’.
and
‘frappe.db.commit()’
It might help.

Coming here with more question.

So, I have a custom DocType, and I’d like the status of to change to “Assigned” when a user is assigned to the document (from the sidebar), indicating someone is working on it. The status field shall remain read-only.

And I’d like the status to change once the document is submitted, to Submitted etc.

Any help is appreciated guys :slight_smile: