Set value for a field from another doctype

Hi,
I need set a value for a field in doctype when I clicks a button on another doctype…
like there is a field in first doctype, and there is a button in second doctype. when I click the button it redirects to the first doctype and update the field value.

but if manually go the first doctype the value need not to update. only if I click the button in second doctype it will need to update.

can anyone know how to set value from one doctype’s field from another doctype or suggest some way to achieve this.

thank you.!

Hi @BalaV,

As per scenario, please apply the client script for that.

frappe.ui.form.on('DocType B', {
    refresh: function(frm) {
        frm.add_custom_button(__('Update Field in DocType A'), function() {
            // Set the value of the field in DocType A
            frappe.db.set_value('DocType A', docname_of_doctype_a, 'field_name', 'New Value');

            // Refresh the current form to reflect the changes
            frm.refresh();
        });
    }
});

I hope this helps.

Thank You!

2 Likes

Thank you . :handshake: :smile: :smile: