I am validating that a subgrid N:N has at least one record before allowing a Contract to be activated via the "Invoice Contract" button using javascript.
function onStatusChange(context) {
var currentRowCount = Xrm.Page.getControl("subgrid_name").getGrid().getTotalRecordCount();
if (currentRowCount == 0) {
Xrm.Page.ui.setFormNotification("There are no Customer Assets listed. ", "ERROR");
Xrm.Page.getAttribute("statecode").setValue(0);
Xrm.Page.getAttribute("statuscode").setValue(1);
}
else{
Xrm.Page.ui.clearFormNotification();
}
}
This all works well except that if the user clicks on the "Invoice Contract" button the Form becomes read only.
I have tried to identify through debug in browser how to prevent it changing without success.
I don't believe the "Invoice Contract" button performs a Save as onSave not triggered when pressed.
My state and status are staying at draft when the "Invoice Contract" button is pressed and notification appears but form is now read only.
Any ideas?





