1
votes

I am using Web API calls to Dynamics 365 to get result for function QuerySchedule. I have tried using this as a bound function as well. But none of them returns the expected result. Below is documentation on this: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/queryschedule?view=dynamics-ce-odata-9

I have tried different resource id, different ways to specify the enum type in the call, fully qualified function name, etc but I always get error.

Following is my call:

https://mycrm.com/api/data/v9.0/QuerySchedule(ResourceId=@p1,Start=@p2,End=@p3,TimeCodes=@p4)?@p1=resourceguid&@p2=2019-01-05T09:27:39Z&@p3=2019-01-05T21:27:39Z&@p4=Available

The output is expected to be QueryScheduleResponse as mentioned in below link: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/queryscheduleresponse?view=dynamics-ce-odata-9

But I keep getting error message:

Object reference not set to an instance of an object.

Could anyone who has done web api calls to Dynamics 365 using OData or has any experience with this kindly help?

1
Can I assume you are using D365 CE v9.2? Maybe you want to simplify your query and put the simplified URL in a browser? - Kelvin

1 Answers

0
votes

Quickly did a browser console test, the code snippet from this blog post works fine.

Pasting part of the snippet from the blog, your code may break as you are passing "Available" instead of ['0'] for TimeCodes.

var requestUrl = "/api/data/v9.0/QuerySchedule(ResourceId=@p1,Start=@p2,End=@p3,TimeCodes=@p4)";
requestUrl += "?@p1=" + context.getUserId().replace("{", "").replace("}", "");
//put Id of resource you want get data for as parameter 1

requestUrl += "&@p2=" + JSON.stringify(start).replace(/"/g, "");
requestUrl += "&@p3=" + JSON.stringify(end).replace(/"/g, "");
requestUrl += "&@p4=" + JSON.stringify(['0']);

Even you can paste this url in your browser address bar to smart test:

Request:

https://test.crm.dynamics.com/api/data/v9.0/QuerySchedule(ResourceId=@p1,Start=@p2,End=@p3,TimeCodes=@p4)?@p1=0EEE678F-C4FF-E711-A959-000D3A1A941E&@p2=2019-01-15T09:27:39Z&@p3=2019-01-15T21:27:39Z&@p4=['0']

You may notice ['0'] turn into [%270%27] but the below expected response will appear.

Response:

{"@odata.context":"https://test.crm.dynamics.com/api/data/v9.0/$metadata#Microsoft.Dynamics.CRM.QueryScheduleResponse","TimeInfos":[{"Start":"2019-01-15T00:00:00Z","End":"2019-01-16T00:00:00Z","TimeCode":"Available","SubCode":"Schedulable","SourceId":"15f40c32-1609-46db-93da-1bbb8eb19c9d","CalendarId":"69b0ee2b-bad7-4b8e-9bcc-d03e76b45a03","SourceTypeCode":4004,"IsActivity":false,"ActivityStatusCode":-1,"Effort":1.0,"DisplayText":""}]}