Announcements
My Following JS not working. Problem with the Highlighted part
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;
if (string) {
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;
}
}
}
I can see you have constructed the query string - 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;
But I cant see it being passed into a HttpRequest to fetch anything (I am assume maybe you are just testing to see if the code runs?)
Currenty the string is always going to be true so it will always be successful and nothing will appear.
if (string) {
ruleResult.IsValid = true;
ruleResult.Message = "Success";
ruleResult.Type = 'success';
}
return ruleResult;
}
Have you tried debugging your code?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,807 Super User 2024 Season 2
Martin Dráb 229,135 Most Valuable Professional
nmaenpaa 101,156