This code checks if form is valid for saving, by going over all required attributes and checking if it contains value.
function IsFormValidForSaving(){
var valid = true;
Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
   if (attribute.getRequiredLevel() == "required") {
      if(attribute.getValue() == null){
          if(valid){
              var control = attribute.controls.get(0);
              alert(control.getLabel() + " is missing a value");
              control.setFocus();
          }
          valid = false; 
} } });
return valid;
}
Another option is using crm system function but then it won't be supported.
fghfgh
ReplyDelete