Hi,
How would I go about ensuring teamResult waits until checkTeam has returned a value in the following code? Writing to the console, I have established the execution order is not as I would hope. I have had success writing this as a single function, but ideally I would like to reuse the checkTeam function.
Console:
undefined
7db988a2-f87c-e911-a98a-00224800c5df
true
Code:
function lockDueDate(executionContext) {
"use strict";
var formContext = executionContext.getFormContext();
var globalContext = Xrm.Utility.getGlobalContext();
var organizationName = globalContext.getClientUrl();
if (organizationName.indexOf("****") >= 0) {
var team = "****";
} else if (organizationName.indexOf("****") >= 0) {
var team = "****";
} else if (organizationName.indexOf("****") >= 0) {
var team = "****";
} else if (organizationName.indexOf("****") >= 0) {
var team = "****";
} else {
return;
}
//if member of team lock due date
var dueDate = formContext.getControl("header_scheduledend");
var teamResult = checkTeam(team);
if (teamResult === false) {
if (dueDate != null) {
dueDate.setDisabled(true);
} else {
return;
}
}
}
//Check to see if user is member of team
function checkTeam(teamId) {
var context = Xrm.Utility.getGlobalContext();
var clientURL = context.getClientUrl();
var req = new XMLHttpRequest();
var userId = context.userSettings.userId.substr(1, 36);
Xrm.WebApi.online.retrieveMultipleRecords("teammembership", "?$select=teammembershipid&$filter=systemuserid eq " + userId + " and teamid eq " + teamId +" ").then(
function success(results) {
for (var i = 0; i < results.entities.length; i++) {
var membership = results.entities[i]["teammembershipid"];
if (membership.length > 0) {
return true;
}
}
return false;
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
*This post is locked for comments
I have the same question (0)