Fetch Field Values on Creation of Document

Hi,

I am relatively new to ERPNext but after skimming over the boards I couldn’t find a response to this question:

When creating a sales order, often BigCommerce prepopulates the addresses with the default billing and shipping address. Some of the Sales Order Fields though, rely on fetching values from the sales order.
These fields are not fetched without manually reinserting the address. So my question is drums

How can I populate these fields as I do in the scripts below, already during the creation of the sales order?

Please find below the fetches I do.

cur_frm.add_fetch(“customer_address”, “email_id”, “sales_invoice_billing_email”);
cur_frm.add_fetch(“shipping_address_name”, “email_id”, “sales_invoice_shipping_email”);
cur_frm.add_fetch(“shipping_address_name”, “warehouse”, “set_warehouse”);
cur_frm.add_fetch(“shipping_address_name”, “warehouse_order_email”, “sales_warehouse_email”);
frappe.ui.form.on(“Sales Order”,“validate”, function(){ for (var i =0; i < cur_frm.doc.items.length; i++){ cur_frm.doc.items[i].warehouse = cur_frm.doc.set_warehouse } cur_frm.refresh_field(‘items’) });

P.S.
If I get some help here I will commit it as an update to the manual in the custom script section.

3 Likes