How to get audit record details using FetchXML

白昼怎懂夜的黑 提交于 2020-01-04 03:50:43

问题


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:


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.



来源:https://stackoverflow.com/questions/32066276/how-to-get-audit-record-details-using-fetchxml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!