Dynamics 365 RetrieveAttributeChangeHistory OData function for audit entity

1

Context

Trying RetrieveAttributeChangeHistory from the Dynamics 365 audit entity. I need some help forming the proper syntax for the OData function on this entity. Since the function is unbound I am having some trouble and run into the error below. Once I solve this I can implement this call in my Java program.

https://myorg.api.crm.dynamics.com/api/data/v9.0/RetrieveAttributeChangeHistory

Error

{
    "error": {
        "code": "0x80040203",
        "message": "Required field 'Target' is missing",
        "innererror": {
            "message": "Required field 'Target' is missing",
            "type": "System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]",
            "stacktrace": "   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, InvocationContext invocationContext, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext, Dictionary`2 optionalParameters)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Execute(OrganizationRequest request, ExecutionContext executionContext)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.ExecuteOperation(CrmODataExecutionContext context, EdmOperation edmOperation, Dictionary`2 parameters, Dictionary`2 boundParameters)\r\n   at Microsoft.Crm.Extensibility.OData.ActionController.ProcessOperationRequest(String operationName, Dictionary`2 operationParameters, EntityReference entityReference, String boundEntityName, String boundEntityType)\r\n   at Microsoft.Crm.Extensibility.OData.ActionController.<>c__DisplayClass12_0.<GetUnboundFunction>b__0()\r\n   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)\r\n   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\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.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.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.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
        }
    }
}
java
rest
dynamics-crm
odata
microsoft-dynamics
asked on Stack Overflow Apr 12, 2019 by greg • edited Apr 17, 2019 by greg

2 Answers

1

I needed to provide the correct parameters to my OData function. There's a Compose Query functions example that uses the LastXHours Function to showcase how PropertyName and PropertyValue needed to be past into the function parens over the URL.

GET [Organization URI]/api/data/v9.0/accounts?$select=name,accountnumber&$filter=Microsoft.Dynamics.CRM.LastXHours(PropertyName=@p1,PropertyValue=@p2)&@p1='modifiedon'&@p2=12

RetrieveAttributeChangeHistory requires the following parameters to properly call it.

  • Target
  • AttributeLogicalName
  • PagingInfo
answered on Stack Overflow Apr 13, 2019 by greg
1

Thanks Greg for this!

Just want to add for those looking for an example of the GET request for the RetrieveAttributeChangeHistory function:

GET [Organization URI]/api/data/v9.0/RetrieveAttributeChangeHistory(Target=@p1,AttributeLogicalName=@p2)?@p1={'@odata.id':'accounts(E7918C3A-B869-E811-8141-480FC8F421A1)'}&@p2='name'
answered on Stack Overflow Aug 8, 2019 by Guillaume

User contributions licensed under CC BY-SA 3.0