How to get audit record details using FetchXML

2019-07-14 02:15发布

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?

1条回答
Deceive 欺骗
2楼-- · 2019-07-14 03:01

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.

查看更多
登录 后发表回答