How fetch one field data from one doctype to another doctype


i have create ‘lease owner’ field on property doctype and property doctype link to lease doctype if i click on plus button of lease on connection tab then property name automatically fetched and then i choose ‘lease customer’ any one of them and save the lease then that ‘lease customer’ name should reflect in to property ‘lease owner’ field

Hello @Rahul7218 You can use “Fetch From” property to achieve this.

@Rahul7218

You have to add Fetch From in the lease Owner field

Example:
[property field name].[lease owner field name]

Exampel 2:

In customer doctype there is one field Pan No and fieldname is pan_no
I want to fetch this field in Sales Invoice at the time of selection of customer
then I have to add fetch from in Sales invoice Pan No field

customer.pan_no

Please check the video (Fetch From - Default Feature: start with 0:55)

hi @Viral_Kansodiya thank you for response
i have try this one but not getting customer name


this also not work

@Rahul7218 Make sure that Lease is a link field!

@Rahul7218 Make sure that Customer is a link field !

@Rahul7218 If u have update the doctype details from the py file then not update the fetch_from field directly so u have update the field manually.

1 Like

Yes i have link to lease and customer but not getting lease customer value

No i am not update doctype details from py file

if both fieldname is same then it would automatically fetch it. I guess its different in your doctypes. like if both field name is “lease_ower” then it will fetch.

do you have any client script for that

i think fetch from is not work here

Try this for backward update in a doctype.

frappe.ui.form.on("Lease", {
  after_save: function (frm) {
    // Get the property ID from the Lease form
    let property_id = frm.doc.property;

    // Get the lease_customer value
    let lease_customer = frm.doc.lease_customer;

    // Debugging: Check values in the console
    console.log("Property ID: ", property_id);
    console.log("Lease Customer: ", lease_customer);

    // Ensure values are not empty or undefined
    if (property_id && lease_customer) {
      // Use frappe.call to update the Property doctype
      frappe.call({
        method: "frappe.client.set_value",
        args: {
          doctype: "Property",
          name: property_id,
          fieldname: { custom_lease_owner: lease_customer },
        },
        callback: function (r) {
          if (!r.exc) {
            frappe.msgprint(__("Lease Owner updated successfully"));
          } else {
            // Debugging: Log the error
            console.log("Error: ", r.exc);
          }
        },
      });
    } else {
      frappe.throw(__("Property ID or Lease Customer is missing."));
      console.log("Missing Property ID or Lease Customer");
    }
  },
});