ODATA ACTIONS
In Dynamics you can decorate the signature of OData Action methods in two ways.
[SysODataActionAttribute("YourODataActionName", false)]
[SysODataActionAttribute("YourODataActionName", true)]
The second parameter can be true or false, as you can see from the previous example.
Case 1
If the second parameter is false, you can call OData Action as following.
Example:
https://Dyamics365URL/data/DataEtityame/Microsoft.Dynamics.DataEntities.YourODataActionName
Case 2
If the second parameter is true you have to provide the Context of the data -entity along with the call. The context identifies the unique record. Suppose you are calling the Customer Groups data entity; you would need to pass the Customer Group Id for the record identification.
Example
https://Dynamics365URL/data/CustomerGroups(dataAreaId='USMF',CustomerGroupId='CG10')/Microsoft.Dynamics.DataEntities.YourODataActionName
Problem:
For the case where second parameter is true, you may face following error message, while making the call to the OData-Action.
No resources were found when selecting for update (The full error message by the end of this post)
The error message is complaining about not being able to find a record on which it can operate (perform OData-Action).
There may be nothing wrong with your code of OData-Action and with your call to the OData-Action. But still, you can face this error and that is exactly what happened to me. On google, they may suggest you that are not passing the correct context/filter for the selection of record.
The other silly reason today I found was that the integration user in the Dynamics not having the Default Company attached to it.
Solution:
Always make sure your integration user has a default company attached to it. Be it USMF or any company of your choice. You will need to go to all users under the system administration module and select the integration user and make sure that a default company has been mentioned for the integration user. If not, attach one and save the record.
Some of you may also wonder about the integration user. Which use is your integration user? Look into the Azure Active Directory applications Setup under the system administration module.
How to reproduce the issue
- Create/consider a data entity.
- Develop/Identify an OData Action for the data entity.
- Make sure the second parameter is set to true in the signature of OData Action.
- Remove the Default company from the Integration User, in the Dynamics.
- Use Postman or any other tools to make a call to OData Action.
Error Message in full
{
"error": {
"code": "",
"message": "An error has occurred.",
"innererror": {
"message": "No resources were found when selecting for update.",
"type": "Microsoft.Dynamics.Platform.Integration.Services.OData.ODataArgumentException",
"stacktrace": " at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateManager.GetActionChangeInfo(IQueryable query, EntityType entityType, Boolean isBatch, ODataBindingKind bindingKind)\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.Update.UpdateManager.CreateInvokable(IQueryable queryable, EntityType entityType, IEdmOperation action, ODataActionParameters parameters, Boolean isBatch)\r\n at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataController.InvokeAction(ODataActionParameters parameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClassc.<GetExecutor>b__6(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.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\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.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\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.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Tracing.Tracers.HttpControllerTracer.<ExecuteAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
*This post is locked for comments