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. Selenium2+python自动化59-数据驱动(ddt)【转载】

    前言 在设计用例的时候,有些用例只是参数数据的输入不一样,比如登录这个功能,操作过程但是一样的.如果用例重复去写操作过程会增加代码量,对应这种多组数据的测试用例,可以用数据驱动设计模式,一组数据对应一 ...

  2. Selenium2+python自动化40-cookie相关操作【转载】

    前言 虽然cookie相关操作在平常ui自动化中用得少,偶尔也会用到,比如登录有图形验证码,可以通过绕过验证码方式,添加cookie方法登录. 登录后换账号登录时候,也可作为后置条件去删除cookie ...

  3. cobbler部署安装

    挂载光驱 # mount /dev/cdrom /mnt/ 安装cobbler所需软件 # yum install cobbler cobbler-web dhcp tftp-server pykic ...

  4. 哦这。。!C语言scanf输入的坑爹之处

    一. 今天闲来无事,跑去A题,本想3sA了poj1004,结果搞了10分钟,最令人困惑的问题就是为什么定义了double类型的变量,但是用scanf输入的时候标识符用%f的话,输入并不能完成,也就是说 ...

  5. 36、Django实战第36天:首页功能开发

    1.编辑users.views.py ... class IndexView(View): """ 首页 """ def get(self, ...

  6. Python __call__内置函数的作用和用法

    开学了进入了实验室,需要协助大师兄做事,主要是OpenStack中的代码解析,但是涉及很多python高级用法,一时间有点麻烦,在做项目的同时慢慢更新博客.这次先写一下__call__的用法,因为经常 ...

  7. oracle null 相关的另外2个方法

  8. [BZOJ2655]calc(拉格朗日插值法+DP)

    2655: calc Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 428  Solved: 246[Submit][Status][Discuss] ...

  9. 【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals

    处理出前缀和,枚举k的幂,然后从前往后枚举,把前面的前缀和都塞进map,可以方便的查询对于某个右端点,有多少个左端点满足该段区间的和为待查询的值. #include<cstdio> #in ...

  10. MAC接普通外置键盘的修改键位的方法

    使用mac电脑已经有一年多,现在对它的喜欢是每天都在增加,甚至有些离不开了.今天突然想接个外置键盘,在使用过程中,遇到一些问题,记录一下. 使用过mac的同学都知道,mac键盘有一个最大的特点是: 比 ...