RetrieveAttributeChangeHistoryRequest 检索对特定属性所做的全部更改

方法示例:
var attributeChangeHistoryRequest = new RetrieveAttributeChangeHistoryRequest
{
Target = new EntityReference(
entity.LogicalName, entity.Id),
AttributeLogicalName = "new_status_lc"
};

            var attributeChangeHistoryResponse =
                (RetrieveAttributeChangeHistoryResponse)plugin.SysService.Execute(attributeChangeHistoryRequest);

            // Display the attribute change history.
            AuditDetailCollection details = attributeChangeHistoryResponse.AuditDetailCollection;
            if (details != null && details.Count > 1 && details[0] != null)
            {
                    Type type = details[0].GetType();
                    Entity oldValueEntiy = type.GetProperty("OldValue").GetValue(details[0], null) as Entity;
                    Entity newValueEntity = type.GetProperty("NewValue").GetValue(details[0], null) as Entity;
                    auditValue.OldValue = oldValueEntiy.Contains(field) ? oldValueEntiy.GetAttributeValue<Money>(field).Value.ToString() : "";
                    auditValue.NewValue = newValueEntity.Contains(field) ? newValueEntity.GetAttributeValue<Money>(field).Value.ToString() : "";
            }
posted @ 2021-11-01 16:15  小芝麻开花  阅读(58)  评论(0编辑  收藏  举报