
Hi,
I have a function in JavaScript which actually sets NULL value in Email_Allowed field if there is no value in "Email" field.
So, the logic mentioned below is working fine in unmanaged solution, but it is not setting null value in managed solution.
function handleAllowedFields(dataField, allowedField) {
return function () {
if (dataField == null || allowedField == null) {
return;
}
if (dataField.getValue() == null) {
allowedField.setValue(null);
allowedField.setRequiredLevel("none");
allowedField.controls.forEach(function (c) {
c.setDisabled(true);
});
} else {
// If dataField is having a value, then contact preference fields
// can have an value as Allow OR DoNotAllow ONLY.
allowedField.controls.forEach(function (c) {
c.setDisabled(false);
});
allowedField.setRequiredLevel("required");
}
}
}
When I debugged it in managed solution, I found that it is working in debug mode but NOT in regular mode. To me, it looks like it is not able to find the control in regular mode.
Help please.
Hi partner,
First of all, how did you get the "dataField" and "allowedField" before entering this function? I suggest to use "formcontext.getAttribute" instead of "Xrm.page".
If you already used formcontext and still can't find the control, you could add a setTimeOut to keep running this function until all the controls have been loaded.
Also you need to add the settimeout function before you get the fields.
setTimeout(function(){//get field by formcontext...}, 3000);
In normal, running js functions in managed or unmanaged solutions should not have differences. So you could also check if there is any other customizations which may affect your js code.
Hope it helps.
Best Regards,
Leo