Fetch field value from one doctype to child table of another doctype

Hello Everyone,

I have created a custom field in the “Sales Invoice Advance” Child Table in Sales Invoice.

Custom Field Label: Mode of Payment.

Custom Field Type: Link

Custom Fieldname: mode_of_payment

My requirement is when I click on “get advance payment” button which is available in the Advance Payment Section, it should fetch the value of Mode of Payment in the “Sales Invoice Advance” table from the payment entry linked to it. How can I achieve this. I have tried this with the below Custom Script. Added this script in the Sales Invoice Doctype

frappe.ui.form.on(“Payment Entry”, “refresh”, function(frm) {
frappe.ui.form.on(“Sales Invoice Advance”, {
“mode_of_payment”: function(frm) {
frm.add_fetch(“mode_of_payment”, “mode_of_payment”, “mode_of_payment”);


Please help with this.

Thanks & Regards,

Hi @Sujay,

have you tried to set “fetch_from” in your custom field to “reference_name.mode_of_payment”?

I had tried that earlier, but the value gets displayed only after I save the document. I want this to get fetched soon after I click the “get advance payment” button.

In that case, you would have to take the change trigger and manually pull the value… Something like

frappe.ui.form.on("Sales Invoice Advance", {
    “reference_name”: function(frm, cdt, cdn) {
            "method": "frappe.client.get",
            "args": {
                "doctype": "Payment Entry",
                "name": frappe.model.get_value(dt, dn, 'reference_name');
            "callback": function(response) {
                var payment_entry = response.message;
                if (payment_entry) {
                    frappe.model.set_value(cdt, cdn, "mode_of_payment", payment_entry.mode_of_payment);

Note that the child table trigger is not cascaded in the main trigger section, but separately below.

maybe thats cause you used a validation or onsave trigger or something like that, or you simply forgot to refresh field after fetching,

share your code snippet so that members can better understand the issue