using System;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Crm.Sdk.Messages;

/// <summary>

    /// 视图

    /// </summary>

    public class UserQueryHelper

    {

        public static readonly string entityName = "userquery";

        public Guid viewid = Guid.Empty;

        public IOrganizationService service;

/// <summary>

        /// 创建视图

        /// </summary>

        public void Create()

        {

            #region fetchXml

            string fetchXml =@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>

                        <entity name='opportunity'>

                        <order attribute='estimatedvalue' descending='false' />

                        <filter type='and'>

                            <condition attribute='statecode' operator='eq'

                            value='0' />

                        </filter>

                        <attribute name='name' />

                        <attribute name='estimatedvalue' />

                        <attribute name='estimatedclosedate' />

                        <attribute name='customerid' />

                        <attribute name='opportunityratingcode' />

                        <attribute name='closeprobability' />

                        <link-entity alias='opportunitycustomeridcontactcontactid'


                            name='contact' from='contactid' to='customerid'

                            link-type='outer' visible='false'>

                            <attribute name='emailaddress1' />

                        </link-entity>

                        <attribute name='opportunityid' />

                        </entity>

                    </fetch>";

            #endregion

            #region layoutXml

            string layoutXml = @"<grid name='resultset' object='3' jump='name' select='1' preview='1' icon='1'>

                                    <row name='result' id='opportunityid'>

                                    <cell name='name' width='150' />

                                    <cell name='customerid' width='150' />

                                    <cell name='estimatedclosedate' width='150' />


                                    <cell name='estimatedvalue' width='150' />

                                    <cell name='closeprobability' width='150' />

                                    <cell name='opportunityratingcode' width='150' />


                                    <cell name='opportunitycustomeridcontactcontactid.emailaddress1'


                                        width='150' disableSorting='1' />

                                    </row>

                                </grid>";

            #endregion

            Entity en = new Entity() { LogicalName = entityName };

            en["name"] = "自己定义商机视图";

            en["returnedtypecode"] = "opportunity";

            en["querytype"] = 0;

            en["fetchxml"] = fetchXml;

            en["layoutXml"] = layoutXml;

            en["querytype"] = 0;

            viewid = service.Create(en);

        }

/// <summary>

        /// 将用户查询分派给还有一用户或团队

        /// </summary>

        /// <param name="assignee">用户或团队引用</param>

        public void Assign(EntityReference assignee)

        {

            AssignRequest request = new AssignRequest();

            request.Target = new EntityReference() { LogicalName = entityName,Id = viewid };

            request.Assignee = assignee;

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

        }

/// <summary>

        /// 运行由 ID 指定的先前保存的查询

        /// </summary>

        public void ExecuteByIdUserQuery()

        {

            ExecuteByIdUserQueryRequest request = new ExecuteByIdUserQueryRequest();

            request.EntityId = new EntityReference() { LogicalName = entityName,Id = viewid };

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

            string result = response.String;

        }

/// <summary>

        /// 删除指定安全主体(用户或团队)对用户查询的全部訪问权限

        /// </summary>

        /// <param name="revokee">用户或团队引用</param>

        public void RevokeAccess(EntityReference revokee)

        {

            RevokeAccessRequest request = new RevokeAccessRequest();

            request.Target = new EntityReference() { LogicalName = entityName, Id = viewid };

            request.Revokee = revokee;

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

        }

/// <summary>

        /// 删除视图

        /// </summary>

        public void Delete()

        {

            service.Delete(entityName, viewid);

        }

}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

crm操作观点的更多相关文章

  1. crm操作业务部门

    using System;     using System.Linq;     using Microsoft.Xrm.Sdk;     using Microsoft.Crm.Sdk.Messag ...

  2. crm操作货币实体

    using System;     using Microsoft.Xrm.Sdk;     using Microsoft.Crm.Sdk.Messages; /// <summary> ...

  3. crm操作权限

    using System;     using Microsoft.Xrm.Sdk;     using Microsoft.Xrm.Sdk.Query;     using System.Colle ...

  4. crm操作知识库文章实体

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

  5. crm操作安全角色

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

  6. crm操作产品实体

    using System;     using Microsoft.Xrm.Sdk;     using Microsoft.Crm.Sdk.Messages; /// <summary> ...

  7. crm操作电子邮件

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

  8. crm操作销售订单实体

    using System;     using Microsoft.Xrm.Sdk;     using Microsoft.Xrm.Sdk.Query;     using Microsoft.Cr ...

  9. crm操作约会实体

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

随机推荐

  1. hdu 4685 Prince and Princess(匈牙利算法 连通分量)

    看了别人的题解.须要用到匈牙利算法的强连通算法 #include<cstdio> #include<algorithm> #include<vector> #pra ...

  2. ORA-16525: the Data Guard broker is not yet available

    DGMGRL> disable configuration;ORA-16525: the Data Guard broker is not yet available Configuration ...

  3. 解决Android Device Chooser 找不到设备问题

    第一种情况: 已经启动了官方的模拟器也进入了Android手机界面,可是在Android Device Chooser 看不到设备,怎么办? 例如以下图所看到的,使用Reset adb 或者在adb所 ...

  4. 安装dotnet core

    CentOS 7.1下安装dotnet core .NET CORE的官方(http://dotnet.github.io/getting-started/)只提供了Windows, Ubuntu14 ...

  5. Swift 简单介绍 - 苹果最新的编程语言

    Swift 真的能够说是最新的编程语言了,2014wwdc刚刚公布,以下来了解一下都有哪些特点. 首先感谢原作者,主要内容是借鉴他的,參考链接 http://zh.lucida.me/blog/an- ...

  6. bellman_ford算法

    给定一个源点,求最短路径,那么存在以源点为根的最短路径树因为最短路径具有最优子结构的性质,所以我们可以先求出树的第一层,然后再求出树的第二层,以此类推bellman_ford算法就是按照这种思想求最短 ...

  7. 从零開始学android&lt;数据存储(1)SharedPreferences属性文件.三十五.&gt;

    在android中有五种保存数据的方法.各自是: Shared Preferences Store private primitive data in key-value pairs. 相应属性的键值 ...

  8. jQuery Ajax: $.post请求示例

    jQuery Ajax: $.post请求示例 leyangjun.html页面 <html> <head> <meta http-equiv="Content ...

  9. 查看hadoop管理页面,修改本地hosts,Browse the filesystem

    问题: hadoop管理界面,ip:50070,中点击Browse the filesystem会出现网页无法访问,看地址栏,是集群中的主机名::50075/browseDirectory.jsp?n ...

  10. Type mismatch: cannot convert from Enumeration&lt;String&gt; to Enumeration&lt;Object&gt;

    完整的错误信息: Description Resource Path Location TypeType mismatch: cannot convert from Enumeration<St ...