I had
an odd error where I was trying to null a lookup field in Javascript in CRM
2013.When the user changed a lookup field, I wanted to blank out a few fields
to make them select those fields again. The fields being nulled were
dependant on selection of the first lookup field and the options and values
they could pick changed.
if
(Xrm.Page.getAttribute("field1").getValue() != null) {
Xrm.Page.getAttribute("field1").setValue(null);
}
if
(Xrm.Page.getAttribute("field2").getValue() != null) {
Xrm.Page.getAttribute("field2").setValue(null);
}
field1 was correctly set to null but field2 refused to be set to null
field1 was correctly set to null but field2 refused to be set to null
I
changed my code to set the required level to none, set field2 to null and then
reset the required level to required.
//I had to set required level to none because assign null wasn't working, might be fixed in future roll ups
//I had to set required level to none because assign null wasn't working, might be fixed in future roll ups
if (Xrm.Page.getAttribute("field1").getValue() != null) {
Xrm.Page.getAttribute("field1").setValue(null);
}
Xrm.Page.data.entity.attributes.get("field2").setRequiredLevel("none");
if (Xrm.Page.getAttribute("field2").getValue() != null) {
Xrm.Page.getAttribute("field2").setValue(null);
}
Xrm.Page.data.entity.attributes.get("field2").setRequiredLevel("required");
No comments:
Post a Comment