using System;

    using System.Linq;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Query;

    using Microsoft.Crm.Sdk.Messages;

    using Microsoft.Xrm.Sdk.Messages;

    using System.Collections.Generic;

/// <summary>

    /// 审核历史记录

    /// </summary>

    public class AuditHistory

    {

        /// <summary>

        /// 检索对特定属性所做的所有更改

        /// </summary>

        /// <param name="service">服务</param>

        /// <param name="Target">记录对象</param>

        /// <param name="attrName">字段名称</param>

        /// 特别说明:字段必须开启审核

        public void RetrieveAttributeHistory(IOrganizationService service, EntityReference target,string attrName)


        {

             RetrieveAttributeChangeHistoryRequest request = new RetrieveAttributeChangeHistoryRequest();

             request.AttributeLogicalName = attrName;

             request.Target = target;

             request.PagingInfo = new PagingInfo() { Count = 1000,PageNumber = 1 };

             RetrieveAttributeChangeHistoryResponse response = (RetrieveAttributeChangeHistoryResponse)service.Execute(request);

             //结果

             AuditDetailCollection auditDetailCollection = response.AuditDetailCollection;

        }

/// <summary>

        /// 索对特定实体所做的所有更改

        /// </summary>

        /// <param name="service">服务</param>

        /// <param name="target">目标记录</param>

        public void RetrieveEntityHistory(IOrganizationService service, EntityReference target)


        {

            RetrieveRecordChangeHistoryRequest request = new RetrieveRecordChangeHistoryRequest();

            request.Target = target;

            request.PagingInfo = new PagingInfo() { Count = 1000,PageNumber = 1 };

            RetrieveRecordChangeHistoryResponse response = (RetrieveRecordChangeHistoryResponse)service.Execute(request);

            //结果

            AuditDetailCollection auditDetailCollection = response.AuditDetailCollection;

        }

/// <summary>

        /// 删除包括在给定结束日期之前创建的审核数据的全部分区

        /// </summary>

        /// <param name="service">服务</param>

        /// <param name="endDate">结束日期</param>

        public void DeleteAudit(IOrganizationService service, DateTime endDate)

        {

            DeleteAuditDataRequest request = new DeleteAuditDataRequest();

            request.EndDate = endDate;

            DeleteAuditDataResponse response = (DeleteAuditDataResponse)service.Execute(request);

        }

/// <summary>

        /// 删除审核记录

        /// </summary>

        /// <param name="service">服务</param>

        /// <param name="auditDetailCollection">记录集合</param>

        public void DeleteAudit(IOrganizationService service, AuditDetailCollection auditDetailCollection)


        {

            if (auditDetailCollection.AuditDetails != null && auditDetailCollection.AuditDetails.Count > 0)


            {

                ExecuteMultiple multiple = new ExecuteMultiple();

                multiple.AddDelete(auditDetailCollection.AuditDetails.Select(a => a.AuditRecord));

                multiple.Execute(service);

            }

        }

/// <summary>

    /// 批量操作

    /// </summary>

    public class ExecuteMultiple

    {

        private int len = 1500;

        private List<ExecuteMultipleRequest> list = new List<ExecuteMultipleRequest>();

public ExecuteMultiple()

        {

            New();

        }

public void New()

        {

            ExecuteMultipleRequest multiple = new ExecuteMultipleRequest()

            {

                Settings = new ExecuteMultipleSettings()

                {

                    ContinueOnError = false,

                    ReturnResponses = true

                },

                Requests = new OrganizationRequestCollection()

            };

            list.Add(multiple);

        }

public void Add(OrganizationRequest request)

        {

            ExecuteMultipleRequest multiple = list.LastOrDefault();

            if (multiple.Requests.Count >= len)

            {

                New();

                multiple = list.LastOrDefault();

                multiple.Requests.Add(request);

            }

            else

            {

                multiple.Requests.Add(request);

            }

        }

public void AddCreate(Entity en)

        {

            CreateRequest request = new CreateRequest() { Target = en };

            Add(request);

        }

public void AddUpdate(Entity en)

        {

            UpdateRequest request = new UpdateRequest() { Target = en };

            Add(request);

        }

public void AddDelete(EntityReference er)

        {

            DeleteRequest request = new DeleteRequest() { Target = er };

            Add(request);

        }

public void AddDelete(Entity en)

        {

            AddDelete(new EntityReference() { LogicalName = en.LogicalName, Id = en.Id });

        }

public void AddDelete(EntityCollection ec)

        {

            if (ec != null && ec.Entities.Count > 0)

            {

                AddDelete(ec.Entities);

            }

        }

public void AddDelete(DataCollection<Entity> list)

        {

            if (list != null && list.Count > 0)

            {

                foreach (Entity en in list)

                {

                    AddDelete(en);

                }

            }

        }

public void AddDelete(IEnumerable<Entity> list)

        {

            if (list != null && list.Count() > 0)

            {

                foreach (Entity en in list)

                {

                    AddDelete(en);

                }

            }

        }

public void Execute(IOrganizationService service)

            {

                foreach (ExecuteMultipleRequest request in list)

                {

                    service.Execute(request);

                }

            }

    }

}

crm查询和删除审核历史记录的更多相关文章

  1. TODO:MongoDB的查询更新删除总结

    TODO:MongoDB的查询更新删除总结 常用查询,条件操作符查询,< .<=.>.>=.!= 对应 MongoDB的查询操作符是$lt.$lte.$gt.$gte.$ne ...

  2. [SQL]查询及删除重复记录的SQL语句

    一:查询及删除重复记录的SQL语句1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select ...

  3. MySQL查询及删除重复记录的方法

    查询及删除重复记录的方法(一)1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select p ...

  4. Oracle 查询并删除重复记录的SQL语句

    查询及删除重复记录的SQL语句 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select  ...

  5. JBPM4入门——5.流程定义的发布、查询、删除

    本博文只是简要对JBPM4进行介绍,如需更详细内容请自行google 链接: JBPM入门系列文章: JBPM4入门——1.jbpm简要介绍 JBPM4入门——2.在eclipse中安装绘制jbpm流 ...

  6. oracle_SQL 实验查询及删除重复记录 依据条件 (row)

    除数据库表中的重复记录 根据条件 ① 创建表准备数据 创建表 tab_test -- Create table create table TAB_TEST ( ID NUMBER, NAME NVAR ...

  7. Hadoop权威指南:HDFS-目录,查询文件系统,删除文件

    Hadoop权威指南:HDFS-目录,查询文件系统,删除文件 [TOC] 目录 FileSystem实例提供了创建目录的方法 public boolean mkdirs(Path f) throws ...

  8. SQL查询和删除重复字段的内容

    --例如: id NAME VALUE 1 a pp 2 a pp 3 b iii 4 b pp 5 b pp 6 c pp 7 c pp 8 c iii --id是主键 --要求得到这样的结果 id ...

  9. 64、django之模型层(model)--建表、查询、删除基础

    要说一个项目最重要的部分是什么那铁定数据了,也就是数据库,这篇就开始带大家走进django关于模型层model的使用,model主要就是操纵数据库不使用sql语句的情况下完成数据库的增删改查.本篇仅带 ...

随机推荐

  1. discuz自定义生成单页面

    在pc端,若要生成一个单页面,有一个比较方便的方法是生成新的专题页,然后diy其中的内容. 不过这种做法有两个缺点 1 url太过冗赘 2 只有一个插入url代码功能,没有文本编辑功能 而且文本框小的 ...

  2. HDU-5451

    Best Solver Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Tota ...

  3. 如何设置Google Chrome的界面显示语言

    昨天不小心,把Chrome浏览器的界面语言换成了中文, 结果换不回去英文了!!! 这是为啥呀? 我本来使用的是英文界面,换成中文却不让换回原来的语言,这怎么也说不过去吧. Google了一会子也没找到 ...

  4. ng2-admin安装问题

    问题一 启动项目出现如下error: 原理: 暂不清晰, 目前认为是项目本身的问题. 项目作者在博文中给出了相应的解决方案. 具体解决方案: 如果之前装过angular-cli需要先卸载:npm un ...

  5. python的ConfigParser读取设置配置文件

    python 读写配置文件在实际应用中具有十分强大的功能,在实际的操作中也有相当简捷的操作方案,以下的文章就是对python 读写配置文件的具体方案的介绍,望你浏览完下面的文章会有所收获. pytho ...

  6. 51nod 1183 编辑距离【线性dp+类似最长公共子序列】

    1183 编辑距离 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 编辑距离,又称Levenshtein距离(也叫做Edit Distance),是指两个 ...

  7. Naming conventions of python

    1.package name 全部小写字母,中间可以由点分隔开,作为命名空间,包名应该具有唯一性,推荐采用公司或组织域名的倒置,如com.apple.quicktime.v2 2.module nam ...

  8. 训练指南 UVA - 11419(二分图最小覆盖数)

    layout: post title: 训练指南 UVA - 11419(二分图最小覆盖数) author: "luowentaoaa" catalog: true mathjax ...

  9. 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)

    layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...

  10. hihocoder Counting Islands II(并查集)

    Counting Islands II 描述 Country H is going to carry out a huge artificial islands project. The projec ...