Fetch data from child table and populate other Doctype


I’ve created a custom DocType as Child table in customers. This custom doctype has two fields: field1 and field2. Every customer will have multiple values in this child table as it displayed as table in Customer DocType. The name of this custom DocType is Origin.

In other Custom Doctype, named Destination, I’ve a link field to Customers Doctype and I want to fetch data from Customer.Origin Doctype based in the value of one field in Destination Doctype.

For example:

if Destination.field3 == “yes”

I want to fetch the value of field1 from Origin Doctype if Origin.field2 is equal to Destination.field3.

So, if related customer in Destination Doctype has in Origin table one row who field2 is equal to Destination.field3 value, I want to fetch the Origin.field1 and populate Destination.field4.

Can anybody point me in the right direction?

Thank you very much for your help.