Child Table Validate

Hello Dears

We have many custom fields in sales order item according to our business

and all that fields are depends on some other fields like

if current product has base so the user have to fill in base color

and i cant make it mandatory field as its depends on if it has base or not

so now we have make a custom field in item master and fetched it to sales order item
so if it has base . base check field will be fetched and base color will appear coz its depends on base filed

now we are trying to validate it before insert to force users fill in the fields by the following script but without luck

frappe.ui.form.on("Sales Order Item", "before_insert", function(frm, cdt, cdn) { 
	var item = frappe.get_doc(cdt,cdn);
	if (item.base && item.base_color.length==0) {
		frappe.throw("Base Color Can`t be empty");
	}

});

any idea ??

  1. Try to use “validate” instead of “before_insert”
  2. Your code / custom script should be in Parent Doctype.
  3. Verify your code correctness against solution suggested in the link
2 Likes

thanks @Pawan it works fine