In a form, we want the Reject Reason to be set as Required if the value in the Option Set field Decision is selected as Reject. I wrote a JS function which is then associated with OnChange of field Decision and I set the Reject Reason field to be Required.
if (decisionOptionSetValue == 100000006 && decisionOptionSetText == "Reject") {
Xrm.Page.getAttribute("new_rejectionreason").setRequiredLevel("required");
}
Now, the above worked fine with no issues.
The problem is if I open the same record, I can happily remove the value from the Reject Reason field (new_rejectionreason) and it will not throw an error because, my code fires only when we have a Change of value of the Decision option set which, in this case, has not happened.
Now, where do check to prevent these?
Option 1: Do I have an OnChange on the new_rejectionreason field so that I check if the value has been changed?
Option 2: Do I do the check as part of OnSave before I save the form and prevent the form from saving (?) and set this field as Required
Option 3: Do I do the check as OnLoad and set the field new_rejectionreason as Required
Any other option?