CRM 2016 oDetails expand by collection

I am trying to extract some data from the new REST API, but I have a strange problem. If I use $ expand in the collection, this will not work.

Request:

GET [Oranization URL]/api/data/v8.0/accounts?$expand=contact_customer_accounts HTTP/1.1 Accept: application/json Content-Type: application/json; charset=utf-8 OData-MaxVersion: 4.0 OData-Version: 4.0 

And the answer is:

 { "error": { "code": "", "message": "Expansion of navigation properties isn\u2019t supported on entity collections.", "innererror": { "message": "Expansion of navigation properties isn\u2019t supported on entity collections.", "type": "Microsoft.Crm.CrmHttpException", "stacktrace": " at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.ThrowIfSelectClauseHasNavigationProperty(SelectExpandClause selectExpandClause, Boolean isCalledFromEntitySet)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entityCollectionName, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetInternal(String entitySetName, String castEntityName, CrmODataExecutionContext context, CrmEdmEntityObjectCollection crmEdmEntityObjectCollection, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()" } } } SelectExpandClause selectExpandClause, Boolean isCalledFromEntitySet) \ r \ n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection (CrmODataExecutionContext context, String entityCollectionName, ODataQueryOptions queryOptions) { "error": { "code": "", "message": "Expansion of navigation properties isn\u2019t supported on entity collections.", "innererror": { "message": "Expansion of navigation properties isn\u2019t supported on entity collections.", "type": "Microsoft.Crm.CrmHttpException", "stacktrace": " at Microsoft.Crm.Extensibility.OData.CrmODataUtilities.ThrowIfSelectClauseHasNavigationProperty(SelectExpandClause selectExpandClause, Boolean isCalledFromEntitySet)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entityCollectionName, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetInternal(String entitySetName, String castEntityName, CrmODataExecutionContext context, CrmEdmEntityObjectCollection crmEdmEntityObjectCollection, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()" } } } 

But if I make this request on one object, then I get the result

 [Organization URL]/api/data/v8.0/accounts(9761dd37-d1b6-e511-80d7-001dd8b71fde)?$expand=contact_customer_accounts 

In previous versions of CRM (2011,2015), this worked fine. Is it possible that MS removes this feature? In fact, the oData 4.0 protocol allows this type of request.

 http://services.odata.org/v4/TripPinServiceRW/People?$expand=Trips 

Why did MS forbid this? The new REST API is useless without this.

+5
source share
1 answer

Although I expect this to be noted in the Microsoft Dynamics CRM Web Interface Restrictions , this is indeed a limitation of the current implementation.

Other users have noticed how you seem that the $ expand clause only works when querying for data from a single record .

I created a proposal that was implemented as part of the Spring 2016 CRM release: Web API: Implement $ expand on collections :

We included this feature in the Spring 2016 Dynamics CRM release. If you request an extension and select in the appropriate collection the answer will contain an empty collection with the following link, which you can then use to programmatically request each of the linked pages. We are actively studying how we can support the $ filter on an extended collection. If your script requires this, please create another one so that we can determine its priority.

+8
source

Source: https://habr.com/ru/post/1240428/


All Articles