Following highlighted part is not working
function newBookingRule(sbContext) {
debugger;
var ruleResult = {
IsValid: true,
Message: '',
Type: 'success'
};
var resourceReqId = sbContext.newValues.ResourceRequirementId;
var resourceId = sbContext.newValues.ResourceId;
var workOrderId = getRecord(resourceReqId, "_msdyn_workorder_value", "msdyn_resourcerequirements");
var WorkTerritoryId = getRecord(workOrderId, "_msdyn_serviceterritory_value", "msdyn_workorders");
var string = "/api/data/v8.2/msdyn_resourceterritory?$select=_msdyn_territory_value,_msdyn_resource_value&$filter=_msdyn_territory_value eq" + WorkTerritoryId + "and _msdyn_resource_value eq" + resourceId;
var result=getRecords(string)
if (result) {
ruleResult.IsValid = true;
ruleResult.Message = "Success";
ruleResult.Type = 'success';
}
return ruleResult;
}
function getRecord(RecordId, Value, Entity) {
var req = new XMLHttpRequest();
req.open("GET", encodeURI(Xrm.Page.context.getClientUrl() + "/api/data/v8.2/" + Entity + "(" + RecordId + ")?$select=" + Value), false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
req.send();
if (req.readyState === 4) {
req.onreadystatechange = null;
if (req.status === 200) {
window.getResult = JSON.parse(req.response);
return getResult[Value];
}
else {
Xrm.Utility.alertDialog(req.statusText);
return null;
}
}
}
function getRecords(newQuery)
{
var req2 = new XMLHttpRequest();
req2.open("GET", encodeURI(Xrm.Page.context.getClientUrl() +newQuery), false);
req2.setRequestHeader("Accept", "application/json");
req2.setRequestHeader("Content-Type", "application/json;charset=utf-8");
req2.setRequestHeader("OData-MaxVersion", "4.0");
req2.setRequestHeader("OData-Version", "4.0");
req2.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
req2.send();
if (req2.readyState === 4) {
req2.onreadystatechange = null;
if (req2.status === 200) {
return true;
} else {
Xrm.Utility.alertDialog(req2.statusText);
return false;
}
}
}