Reputation: 21
I have two fields : Cobertura and other 3 (lets call it x,y,z) If cobertura value is 150 or 160 I need to make the other 3 fields required and not allowed to save before fill these field, using java script in CRM 11. Using set required level will work for me? What exactly this function does?
Upvotes: 1
Views: 10204
Reputation: 15128
Yes, the setRequiredLevel
function will work in your case. The function changes the requirement level of the field (possible values are none
, recommended
, required
)
you need to check the Cobertura value inside OnLoad
and OnChange
event:
var cobertura = Xrm.Page.getAttribute("cobertura").getValue();
if (cobertura == 150 || cobertura == 160) {
Xrm.Page.getAttribute("x").setRequiredLevel("required");
Xrm.Page.getAttribute("y").setRequiredLevel("required");
Xrm.Page.getAttribute("z").setRequiredLevel("required");
} else {
Xrm.Page.getAttribute("x").setRequiredLevel("none");
Xrm.Page.getAttribute("y").setRequiredLevel("none");
Xrm.Page.getAttribute("z").setRequiredLevel("none");
}
Upvotes: 5
Reputation: 179
Essentially the same as Guido's just refactored
function coberturaSetRequired()
{
var cobertura = Xrm.Page.getAttribute("cobertura");
var x = Xrm.Page.getAttribute("x");
var y = Xrm.Page.getAttribute("y");
var z = Xrm.Page.getAttribute("z");
var isRequired = "none";
if (!cobertura) return;
if (cobertura.getValue() == 150 || cobertura.getValue() == 160)
{
isRequired = "required";
}
x.setRequiredLevel(isRequired);
y.setRequiredLevel(isRequired);
z.setRequiredLevel(isRequired);
}
Upvotes: 3
Reputation: 7918
Function setRequiredLevel("required")
makes the data attribute required. The label of every control field on the web form displaying the attribute will get an asterisk (*) appended to the label text. The user will not be able to save the data on the form as long as the attribute remains empty.
Upvotes: 0