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!");
    }

  • 相关阅读:
    [两个数]最大公约(因)数和最小公倍数
    【curl】【php】curl报错,错误代码77,CURLE_SSL_CACERT_BADFILE (77)解决方法
    【杂项】【旅行】旅行必备
    【windows】【php】【nginx】windows 开机自启动nginx php 及nginx php配置
    【mysql】linux, mac mysql数据库root 密码忘记修改
    【mysql】 load local data infield 报错 ERROR 1148 (42000): The used command is not allowed with this MySQL version
    【mysql】配置 选项文件
    【发布相关】【心得体会】发布的注意事项-20180921
    【php】【运算符】位移运算符
    【php】运算符优先级界定
  • 原文地址:https://www.cnblogs.com/jiapinlog/p/13744275.html
Copyright © 2011-2022 走看看