Fetch value of fieldname from another doctype

I am making customized print format for Delivery Note. I create one
fieldname"so_no" in Doctype “Delivery Note”,
and plan to fetch value from
fieldname “against_sales_order” in Doctype “Delivery Note Item”

So what my step is:

  1. create field name “so_no”, type is Data;
  2. create script in Custom Script : cur_frm.add_fetch(‘Delivery Note Item’,‘against_sales_order’,‘so_no’)

But it is not working, SO NO in custom print format shows “None”. Please check the effect and give me some instruction.

1 Like

@Gavin_Ji Hi try having var1 = frm.doc.{fieldname} on each field you need and then concatenate them

i still a little confused. Sorry i am new in ERPNEXT.

  1. Create so_no in Delivery Note, and input code: var1 = frm.doc.{against_sales_order}

cur_frm.add_fetch arguments are in-correct all the argument should be valid fieldname and the first argument in your case is the doctype name.

and using depends on you can only set the field hidden.

can you please tell me what are you trying ?

Thanks, Makarand

Thank you for your reply. I am stuck in this issue for more than one week, So can you help me?
Can i add your skype Id, and explain more?

@makarand_b can you give me your skype ID?

Hi @Gavin_Ji! Had similar use case but with PO. I wanted to auto populate it in Parent in Purchase Receipt. What I did is I created Purchase_Order fieldname. So for Sales Order, please make you field name to Sales_Order. This will be auto-populated when crated DN from SO. Also, if this wont work, you can create a pyhton script validaiton on save:

def so_validate(doc, method):

    so_no = frappe.get_doc("""Select agaisnt_sales_order from `tabDelivery Note Item` where parent = %s""", 
    doc.so_no = so_no

Hope this helps!

Below custom script is workable in my case. Thank @makarand_b, and also thank @creamdory

frappe.ui.form.on("Delivery Note", "validate", function(frm) {
sales_orders = []
$.each(frm.doc.items, function(idx, row) {
inList(sales_orders, row.against_sales_order) ? "": sales_orders.push(row.against_sales_order)
frm.set_value("so_no", sales_orders.join(","))
1 Like