Validation Rules in Child Table using Custom Script

Hi Everyone,

Is there any way to put validation rules on the child table using script.

I am doing some calculation in Expense Claim Form by adding few custom fields km and claim_amount.

Now, I want that the claim amount should not exceed the sanctioned_amount.

Below is my code, I am using for calculations.

frappe.ui.form.on("Expense Claim Detail","claim_amount", function(frm, cdt, cdn) { 
var d =locals[cdt][cdn]
var item=frappe.get_doc(cdt,cdn);
if(d.expense_type=="Local Conveyance"){
frappe.model.set_value(cdt, cdn, "claim_amount", item.km*item.rate);
cur_frm.refresh_fields();
}
});

Regards
Ruchin Sharma

Try this:

frappe.ui.form.on("Expense Claim Detail", "claim_amount", function(frm, cdt, cdn) { 
	var item = frappe.get_doc(cdt,cdn);
	if (item.sanctioned_amount && item.claim_amount > item.sanctioned_amount) {
		frappe.throw("Claim Amount cannot be greater than Sanctioned Amount");
	}
	
	if(item.expense_type=="Local Conveyance") {
		frappe.model.set_value(cdt, cdn, "claim_amount", item.km * item.rate);
	}
});