码迷,mamicode.com
首页 > 其他好文 > 详细

crm2011查询审核记录

时间:2014-06-08 04:40:28      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:crm2011查询审核记录   crm2011   

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Crm.Sdk.Messages;

    /// <summary>
    /// 查询审核记录
    /// </summary>
    public class RetrieveRecordChangeHistoryRequestHelper
    {
        public void Retrieve(IOrganizationService service,string entityName,Guid id)
        {
            RetrieveRecordChangeHistoryRequest changeRequest = new RetrieveRecordChangeHistoryRequest();
            changeRequest.Target = new EntityReference() { LogicalName = entityName,Id = id };

            RetrieveRecordChangeHistoryResponse changeResponse = (RetrieveRecordChangeHistoryResponse)service.Execute(changeRequest);

            AuditDetailCollection details = changeResponse.AuditDetailCollection;
            if (details != null && details.AuditDetails.Count > 0)
            {
                foreach (AuditDetail detail in details.AuditDetails)
                {
                    System.Console.WriteLine(detail.GetType());
                    DisplayEntity(detail.AuditRecord, "AuditRecord");
                    if (detail.GetType() == typeof(AttributeAuditDetail))
                    {
                        AttributeAuditDetail attrDetail = (AttributeAuditDetail)detail;
                        foreach (string item in attrDetail.InvalidNewValueAttributes)
                        {
                            System.Console.WriteLine(item);
                        }
                        DisplayEntity(attrDetail.NewValue, "NewValue");
                        DisplayEntity(attrDetail.OldValue, "OldValue");
                    }
                    if (detail.GetType() == typeof(RelationshipAuditDetail))
                    {
                        RelationshipAuditDetail shipDetail = (RelationshipAuditDetail)detail;
                        System.Console.WriteLine("RelationshipName" + shipDetail.RelationshipName);
                        if (shipDetail.TargetRecords != null && shipDetail.TargetRecords.Count > 0)
                        {
                           foreach(EntityReference item in shipDetail.TargetRecords)
                           {
                               System.Console.WriteLine("LogicalName: " + item.LogicalName + ",Name: " + item.Name);
                           }
                        }
                    }
                }
            }

        }

        public void DisplayEntity(Entity entity,string label)
        {
            System.Console.WriteLine("display" + label + "start!");
            var keyArray = entity.Attributes.Keys;
            foreach (string name in keyArray)
            {
                System.Console.WriteLine("attributeName: " + name + ",attributeValue: " + entity.Attributes[name]);
            }
            System.Console.WriteLine("display" + label + "end!");
        }
    }

crm2011查询审核记录,布布扣,bubuko.com

crm2011查询审核记录

标签:crm2011查询审核记录   crm2011   

原文地址:http://blog.csdn.net/y_f123/article/details/29179833

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!