static void Main(string[] args)
{
CrmServiceClient service = new CrmServiceClient("xxx");
CrmServiceClient.MaxConnectionTimeout = new TimeSpan(0, 10, 0);
EntityReference entityReference = new EntityReference("xxxx", new Guid("xxx"));
ShowAttributeChangeHistory(service, entityReference, "xxx");
}
static void ShowAttributeChangeHistory(IOrganizationService svc,
EntityReference target,
string columnLogicalName)
{
RetrieveAttributeChangeHistoryRequest req =
new RetrieveAttributeChangeHistoryRequest
{
Target = target,
AttributeLogicalName = columnLogicalName,
PagingInfo = new PagingInfo
{
PageNumber = 1,
Count = 1,
ReturnTotalRecordCount = true
}
};
RetrieveAttributeChangeHistoryResponse resp =
(RetrieveAttributeChangeHistoryResponse)svc.Execute(req);
var auditDetailCollection = resp.AuditDetailCollection.AuditDetails.ToList();
if (auditDetailCollection.Count > 0)
{
AttributeAuditDetail auditRecord = (AttributeAuditDetail)auditDetailCollection[0];
Entity oldRecord = auditRecord.OldValue;
Entity newRecord = auditRecord.NewValue;
Console.WriteLine(newRecord.Contains("xxxx") ? newRecord["xxxxn"].ToString() : "");
Console.WriteLine(oldRecord.Contains("xxxx") ? oldRecord["xxxx"].ToString() : "");
}
}
查询Dynamics 365的Audit History
于 2023-05-31 16:39:57 首次发布