Hi all,
I am trying to use the OOB action "msdyn_RetrieveResourceAvailability" via JS. But getting error 'Object reference not set to an instance of an object'. Has anyone else tried this successfully/unsuccessfully? This action will return collection object. I am mentioning the code below as well as the microsoft document.
https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/msdyn_retrieveresourceavailability?view=dynamics-ce-odata-9
All help appreciated!
function GetResource()
{
var parameters = {};
parameters.RealTimeMode = true;
parameters.Duration = 1122;
parameters.IgnoreDuration = true;
parameters.IgnoreTravelTime = true;
parameters.AllowOverlapping = true;
parameters.Radius = 2211;
parameters.StartTime = new Date("01/24/2018 04:00:00").toISOString();
parameters.EndTime = new Date("01/30/2018 08:00:00").toISOString();
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/msdyn_RetrieveResourceAvailability", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
debugger;
req.onreadystatechange = null;
if (this.status == 200 || this.status == 204) {
var results = JSON.parse(this.response);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(parameters));
}
Thank you
Regards,
AW