Validation on value update

I have 2 custom field (sales stage, commercial stage) depends on the selection of this 2 fileds another field called stage is populated
now I need to make a validation on stage if it’s has a value form commercial stage do not update form sales stage
I try this script but not working

frappe.ui.form.on("Sales Order Item", {
	refresh: function(frm) {
		if (frm.doc.stage == "90") {
			frm.doc.items.forEach(function(item) {
				stage = flt(commercial_stage) - 0;
			});
			frm.refresh_field("items");
		}
	}
});

Your trigger is set on “Sales Order Item”, but refers to frm.doc.items, which only the parent DocType “Sales Order” has. Something like

frappe.ui.form.on("Sales Order", {
	validate: function(frm) {
		if (frm.doc.stage == "90") {
			frm.doc.items.forEach(function(item) {
				var stage = item.commercial_stage - 0;
                            frappe.model.set_value(item.doctype, item.name, "stage", stage);
			});
			frm.refresh_field("items");
		}
	}
});

I am still not quite sure what you are trying to achieve, but I hope this helps to get there :wink: