How to get audit record details using FetchXML
Asked Answered
D

1

4

Using this query im able to retrieve audit records in Microsoft Dynamics CRM online

<fetch version="1.0" >
  <entity name="audit" >
    <all-attributes/>
  </entity>
</fetch>

But this lacks the info about what happened in the operation, more specificly the old value and new value of the column changed. This data is shown when i use the audit tool in the settings of the regular interface, so the data is present. Does anyone know how to fetch it? Is there another entity im missing?

Duprey answered 18/8, 2015 at 7:33 Comment(0)
N
3

Audit records only keep track of the old values. So, when an attribute is modified, only its old value is stored in the audit table.

A new value must be derived by either getting it from the live entity record or (when the value was modified multiple times) by getting the old value of a succeeding audit record for that entity. The old value can be found in the ChangeData field of the Audit entity.

Reconstructing the entity history using the Audit entity directly will require a lot of work and is in most scenarios not necessary. Instead you can use the RetrieveRecordChangeHistoryRequest. The corresponding RetrieveRecordChangeHistoryResponse has an AuditDetail collection. Items in the collection that are of type AttributeAuditDetail contain OldValue and NewValue properties giving you the information you need.

Nipping answered 18/8, 2015 at 9:0 Comment(4)
ok, this makes sense, any idea on how to get the old value? there doesnt seem to be a column for it. The data is more related to operations than the actual contentDuprey
The old value is in the ChangeData field, but you may prefer using the RetrieveRecordChangeHistoryRequest instead. I extended my answer.Nipping
it all sounds like c# functions but some googling shows i can do these calls via JavaScript too, thank you for pointing me in this directionDuprey
Request en Response objects are part of the CRM web service's data contract, but yes, they are most often used in the .NET world. Glad I could help.Nipping

© 2022 - 2024 — McMap. All rights reserved.