Hey guys so I am trying to unlock and lock all the field on a form based some condition
I have a field shows the current user so I am saying if sup == userCurrent lock all the field
and if officer == userCurret unlock all the field field
so I did not get any script error, but code does not lock the field when the lock condition is met
it unlock all the field regardless of condition
if anyone can help and feedback is appreciated Thanks
function Role(){
var activeStage = Xrm.Page.data.process.getActiveStage();
var name = activeStage.getName();
var PSRstatus = Xrm.Page.getAttribute("psr_psrstatus").getText();
var Lksup = Xrm.Page.getAttribute("psr_reportedtoid").getValue();
var Lkofficer = Xrm.Page.getAttribute("psr_reportingofficer").getValue();
//var UserName = Xrm.Page.context.getUserName();
var userCurrent = Xrm.Page.data.entity.attributes.get("psr_currentuser").getValue();
if ((Lkofficer != null) && (Lksup != null)){
var officer = Lkofficer[0].name;
var sup = Lksup[0].name;
if ((PSRstatus == "Return (1st)" || PSRstatus == "Return (2nd)") &&
(sup == userCurrent) && (name == "In-Progress"))
{
setReadOnlyFields();
}else if ((PSRstatus == "Return (1st)" || PSRstatus == "Return (2nd)") &&
(officer == userCurrent) && (name == "In-Progress"))
{
unlockFormFields();
}
}
function setReadOnlyFields() {
Xrm.Page.data.entity.attributes.forEach(function (attribute) {
attribute.controls.get().forEach(function (control) {
if (control) {
control.setDisabled(true);
}
});
});
}
function unlockFormFields()
{
Xrm.Page.data.entity.attributes.forEach(function (attribute) {
attribute.controls.get().forEach(function (control) {
if (control) {
control.setDisabled(false);
}
});
});
}
}
It help you to unlock all field on Javascript it is working i also use this here apkpouch.com/.../