I started doing some MS CRM work and been googling about it A LOT. This is a problem I haven’t seen clearly described, so here is my take. Feel free to correct me or improve the solution!
This is a pretty common scenario: let’s say we have a pick list. If a value from this pick list is selected, we want to make sure, that some other field has a value.
Form OnLoad
// save original value, so we can do rollback in OnChanged event if necessary
originalValue = crmForm.all.<my_picklist>.DataValue;
Picklist OnChange
var complaintStatus = crmForm.all..<my_picklist>;
var closedDate = crmForm.all.<my_other_field>;
if (complaintStatus.DataValue != null) {
if (complaintStatus.DataValue == "3") // closed
{
if (closedDate.DataValue == null)
{
alert("Closed Date value must be specified, if you want to set status to Closed.");
event.returnValue = false;
complaintStatus.DataValue = originalValue;
complaintStatus.SetFocus();
}
else
{
originalValue = complaintStatus.DataValue;
}
}
}