Custom Link Field seems empty


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() {
		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;

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).

1 Like

Hi Francisco

did you get any solution for the validation ‘if the field is empty’?


Try with something like
!frm.doc.sales_invoice or frm.doc.sales_invoice without using == “”

1 Like

I just found out about this too :slight_smile:

It seems that the empty fields are not loaded. So we should address them by using !fieldname (as in no field) and not by fieldname=="" (as in blank field).

Am I correct?