问题
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