Automatic Selection of Warehouse in Sales Invoice Item

Hello Everyone. Please can someone help me to write a client script for a sales invoice doctype that selects different warehouse automatically when brand changes. This is what i have but it’s not working.

frappe.ui.form.on(“Sales Order”, { refresh(frm) { // your code here } });
frappe.ui.form.on(“Sales Order Item”, { brand: function(frm, cdt, cdn) { var child = locals[cdt][cdn]; if (child.brand === ‘Green’) { frappe.model.set_value(cdt, cdn, “warehouse”, “Green Warehouse”); } else if (child.brand === ‘Red’) { frappe.model.set_value(cdt, cdn, “warehouse”, “Red Warehouse”); } } });

Please any help will be appreciated.

why does it not work? any errors in the browser console?
is your code actually called?

maybe you can paste your code formatted - would help reading and understanding.

Thank you… i have figured out the problem.

I don’t know why, but i notice that it doesn’t work with the ERPNext brand field , so i have to create my own brand field and call the value using item_code.brand. And started working… Thank you

Would you mind sharing your code so that others can learn from you?

It’s the same code…i just created my own brand field instead of using the one created in ERPNext…Then the brand field i created can now be called using item_code.brand

1 Like