Getting Customer Fields from Delivery Note?

I need to write a validation code in the Delivery Note. For a start, I am trying with this code

frappe.ui.form.on(“Delivery Note”, {
validate: function(frm) {
msgprint(frm.doc.customer.customer_name);
}
});

If I do frm.doc.customer, it prints the customer name. But if I do like the code above, the message box does not show up at all. It seems that I can’t get any fields from the Customer object using the syntax above. What is the correct way of getting fields from an object contained in a document?

@nanto_himawan

In your above code use -
frm.doc.fieldname , to access particular field from current form.
But there is no field like customer.customer_name.
Just use frm.doc.customer or frm.doc.customer_name

1 Like

@nanto_himawan , Try with this syntax -

frappe.ui.form.on("Delivery Note", "validate", function(frm,doc) {
    	msgprint(frm.doc.customer);	
});
1 Like

Ok…I resolved it. So it seems like the customer field in the delivery note is not an object reference. So we cannot do something like frm.doc.customer.customer_name. We should instead do:

frappe.ui.form.on(“Delivery Note”, {
validate: function(frm) {
// msgprint(frm.doc.customer.customer_name);
frappe.call({
“method”: “frappe.client.get”,
args: {
doctype: “Customer”,
name: frm.doc.customer
},
callback: function (data) {
msgprint(data.message.customer_name);
}
})
}
});