Auto-populate fields depending on selection of other field

Is there a way to auto-populate fields on a document upon selection of an option from another field?

For example.
When creating a New Payment Entry.

When selecting Payment Type to “Pay”, I would like Mode of Payment to automatically select:

  • Mode of Payment to “Check”
  • Party Type to “Supplier”

Hi,

Please put the below code in client script.

frappe.ui.form.on("Payment Entry", {
    payment_type: function(frm) {
        if (frm.doc.payment_type == "Pay") {
            frm.set_value("party_type", "Supplier");
            frm.set_value("payment_type_cheque", 1);
        }
    }
});
1 Like

Hi @dfranco,

Please replace this line.

frm.set_value("mode_of_payment", 'Cheque');
// Please update / check your spell of the Cheque.

Thank You!

2 Likes

Thank you all for your input.
I was able to get this to work.
I wanted to trigger this upon change on the Payment Type field so I had to modify the code a bit.
Here is the final code I used.

frappe.ui.form.on("Payment Entry", {
    payment_type(frm){
        if (frm.doc.payment_type == "Pay") {
            frm.set_value("party_type", "Supplier");
            frm.set_value("mode_of_payment", "Check");
        }
    }
})