Hello,
I’ve placed a link custom field to Sales Invoice at Delivery Note, and filter data with:
frappe.ui.form.on("Delivery Note", "refresh", function(frm) {
cur_frm.fields_dict['sales_invoice'].get_query = function(doc) {
return {
filters: [
['Sales Invoice', 'customer', 'in', doc.customer],
]
}
}
});
Works good. Then, to populate the “sales invoice item” table to Delivery Note, used:
frappe.ui.form.on("Delivery Note", "sales_invoice", function(frm) {
frappe.model.with_doc("Sales Invoice", frm.doc.sales_invoice, function() {
if(frm.doc.sales_invoice){
var tabletransfer= frappe.model.get_doc("Sales Invoice", frm.doc.sales_invoice)
$.each(tabletransfer.items, function(index, row){
d = frm.add_child("sales_invoice_table");
d.item_code = row.item_code;
d.item_name = row.item_name;
d.description = row.description;
cur_frm.refresh_field("sales_invoice_table");
})
}
});
});
Everything goes fine. But if I try to avoid to submit if the link field is blank by:
frappe.ui.form.on("Delivery Note", {
validate: function(frm) {
if(frm.doc.sales_invoice == ""){
msgprint("Sales Invoice number required");
validated = false;
}
});
It’s not working, the Delivery Note can be saved and submitted, it seems like the link field has some value when doc loads, but it’s not visible.
How can I know that value? The link field seems to be blank.
Can the link custom field be set as ‘mandatory’ using a js custom script? (I can’t set as ‘mandatory’ at its properties, because would interfere with many other variables).