Hello
I need to disable a field on a form using JS if a current user isn't member of some specific team.
I wrote this code:
disableField(executionContext){
var formContext = executionContext.getFormContext();
var currentUserId = formContext._globalContext._userSettings.userId;
var fetchResult;
var fetchXML = "?<fetch mapping='logical' version='1.0'>"
+"<entity name='team'>"
+ "<attribute name='name'/>"
+ "<filter>"
+ "<condition attribute='systemuserid' operator='eq' value='{D6470EA5-16D7-EB11-BACB-000D3A1F9C1B}' />"
+ "<condition attribute='name' operator='eq' value='Private access to notes' />"
+ "</filter>"
+ "<link-entity name='teammembership' from='teamid' to='teamid' link-type='inner'/>"
+"</entity>"
+"</fetch>";
var fetchXML2 = `
?fetchXml=
<fetch mapping='logical' version='1.0'>
<entity name='team'>
<attribute name='name'/>
<filter>
<condition attribute='systemuserid' operator='eq' value=${currentUserId} />
<condition attribute='name' operator='eq' value='Private access to notes' />
</filter>
<link-entity name='teammembership' from='teamid' to='teamid' link-type='inner'/>
</entity>
</fetch>
`;
Xrm.WebApi.retrieveMultipleRecords("team", fetchXML).then(
function success(result) {
if(result.entities.length > 0){
debugger;
formContext.getControl("description").setDisabled = true;
}
},
function (error) {
console.log(error.message);
}
);
alert(fetchResult);
},
Unfortunatelly, I couldn't understand why it doesn't work. All code (including debugger) doesn't work in condition block. Which problems with executing do I have? Also I don't know how to write fetchXML in such way as split fetch by lines and have opportunity to use construction like this: ${currentUserId}. If I use fetch2 so I have error when I load contact form. How can I solve these problems?