I’m very new to JS development, I was trying to achieve the following in the else but is not getting executed its not working in Dynamics 365. Maybe syntax wrong… Please advise.
I want to achieve the following if Grant Intention Type not equals post and Current Funding status = post and check user role equals Support Business Advisor then unlock field activity code field. The first if works ok. However this is not working I dont think my else condition even getting hit.
I can create the same function for the 1 role only but this duplicates code I believe.
Please advise.
function unLockNonSalaryCostFieldsBasedOnRolesTeams(executionContext) {
const formContext = executionContext.getFormContext();
const roles = ["Service Ops User", "DocuSignUser", "Geographic Enhanced User", "Support Business Advisor"];
// Store Security Roles
const userRoles = Xrm.Utility.getGlobalContext().userSettings.roles;
const hasRole = userRoles.get().some(r => roles.indexOf(r.name) != -1);
const currentFundingStatus = formContext.getAttribute("fsdyn_fundingstatus").getValue();
const grantIntentionType = formContext.getAttribute("fsdyn_grantintentiontype").getValue();
//get the name of currently lookup field
const grantIntentionTypeLookUpValueName = grantIntentionType[0].name;
if (grantIntentionTypeLookUpValueName !== "Post" && currentFundingStatus === FundingStatus.Proposed) {
formContext.getControl("fsdyn_amount").setDisabled(!hasRole);
formContext.getControl("fsdyn_fundingperiodmonths").setDisabled(!hasRole);
}
else {
if (grantIntentionTypeLookUpValueName !== "Post" && currentFundingStatus === FundingStatus.Proposed) {
formContext.getControl("fsdyn_activitycode").setDisabled(!hasRole);
}
}
}
I tried else condition to execute induvidualy howver check Support Business Advisor role only, do I need to store this another var?