zoukankan      html  css  js  c++  java
  • dynamics crm 共享取消共享操作

    //改文章参考了http://www.mamicode.com/info-detail-209704.html

    Entity entity = (Entity)context.InputParameters["Target"]; //使用该方式,只有改变了属性值才可以获取
    //获得前期事件和后期实体映像
    Entity preEntity = (Entity)context.PreEntityImages["Accountname"]; //操作之前
    Entity postEntity = (Entity)context.PostEntityImages["Accountstage"];//操作之后
    使用该方式的话就不用在插件里面,再取一次实体的其它属性了,会将属性值传入插件

    注意的是,在创建,删除中不可使用。


    可参考该篇文章 https://www.bbsmax.com/A/1O5Eook3z7/
    //例子:当前客户共享团队 客户就是指定共享的实体 而团队就是要求共享的实体


    共享调用:
    EntityReference Record = new EntityReference { Id = entity.Id, LogicalName = entity.LogicalName };
    Grant(adminService, (EntityReference)entity["tm_centralize"], Record);


    共享方法
    //service:服务
    //teamOrSystem,:要求共享的实体
    //Record:指定共享的实体
    private static void Grant_Read(IOrganizationService service, EntityReference teamOrSystem, EntityReference Record)
    {
    GrantAccessRequest grantAccessRequest = new GrantAccessRequest
    {
    PrincipalAccess = new PrincipalAccess
    {
    Principal = teamOrSystem,
    AccessMask = AccessRights.ReadAccess | AccessRights.WriteAccess //赋予的权限
    },
    Target = Record,
    };

    service.Execute(grantAccessRequest);

    }

    //取消共享
    Entity Pusers = service.Retrieve("Account", users.GetAttributeValue<EntityReference>("Accountid").Id, new ColumnSet("tm_centralize"));
    RevokeUser(service, entPre.GetAttributeValue<EntityReference>("tm_centralize"), new EntityReference(entPre.LogicalName, entPre.Id));

    private void RevokeUser(IOrganizationService service, EntityReference teamOrSystem, EntityReference Record)
    {
    RevokeAccessRequest revokeAccessRequest = new RevokeAccessRequest
    {
    Revokee = teamOrSystem,
    Target = Record,
    };

    service.Execute(revokeAccessRequest);

    }

    //查询单条
    EntityReference entity = (EntityReference)context.InputParameters["Target"];
    Entity aaccountTargetEntity = adminService.Retrieve("tm_purchaseamount", entity.Id, new ColumnSet(new string[] { "tm_year", "tm_account" }));

    plugin中查询
    string mFetchXml = string.Format(@"
    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='tm_purchaseamount'>
    <attribute name='tm_purchaseamountid' />
    <attribute name='tm_name' />
    <attribute name='createdon' />
    <order attribute='tm_name' descending='false' />
    <filter type='and'>
    <condition attribute='tm_year' operator='eq' value='{0}' />
    <condition attribute='tm_account' operator='eq' uiname='=C=' uitype='account' value='{1}' />
    <condition attribute='statecode' operator='eq' value='0' />
    </filter>
    </entity>
    </fetch>
    ", ((OptionSetValue)entity["tm_year"]).Value.ToString(), ((EntityReference)entity["tm_account"]).Id.ToString());


    EntityCollection accountEntites = adminService.RetrieveMultiple(new FetchExpression(mFetchXml));
    if (accountEntites.Entities.Count > 0)
    {
    throw new InvalidPluginExecutionException( ((OptionSetValue)entity["tm_year"]).Value.ToString() + " Year already exists!");
    }

  • 相关阅读:
    痞子衡嵌入式:单片机AI的春天已来,ARM Cortex-M55发布了
    《痞子衡嵌入式半月刊》 第 1 期
    痞子衡嵌入式:ARM Cortex-M内核那些事(6)- 系统堆栈机制
    痞子衡嵌入式:嵌入式里堆栈原理及其纯C实现
    将博客搬至CSDN
    痞子衡嵌入式:知名半导体MCU大厂软件开发C代码规范
    痞子衡嵌入式:语音处理工具pzh-speech诞生记(4)- 音频录播实现(PyAudio)
    痞子衡嵌入式:语音处理工具pzh-speech诞生记(2)- 界面构建(wxFormBuilder3.8.0)
    痞子衡嵌入式:ARM Cortex-M内核那些事(3.2)- 为Security而生(M23/33/35P)
    痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU外设那些事(2)- 百变星君FlexRAM
  • 原文地址:https://www.cnblogs.com/jiapinlog/p/13744275.html
Copyright © 2011-2022 走看看