zoukankan      html  css  js  c++  java
  • Dynamics CRM Trigger plugin for N:N relationships

          博客原文:https://demystifyingcrm.wordpress.com/2014/12/17/trigger-plugin-for-nn-relationships-in-dynamics-crm/

    wordpress在国内访问有点困难,怎么访问作为技术的你应该懂的


        下面分享个我的示例,有助于你的理解,parameters总共有3个,Relationship(用来表示当前n:n关系的关系名称,见下面截图),Target和RelatedEntities分别对应的是两个实体,具体的还是看下面的代码就好

     public void Execute(IServiceProvider serviceProvider)
            {
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);
                if (context.MessageName == "Associate")
                {
                    if (context.Depth > 1)
                    {
                        return;
                    }
                    Relationship entityRelationShip = (Relationship)context.InputParameters["Relationship"];
                    if (entityRelationShip.SchemaName == "ubg_branch_product")//产品与分公司N:N的关联
                    {
                        EntityReferenceCollection RelatedEntity = (EntityReferenceCollection)context.InputParameters["RelatedEntities"];
                        Entity product = service.Retrieve(RelatedEntity[0].LogicalName, RelatedEntity[0].Id, new ColumnSet("ubg_approvestate"));
                        if (product.Attributes.Contains("ubg_approvestate") && ((OptionSetValue)product["ubg_approvestate"]).Value != 1)
                        {
                            throw new InvalidPluginExecutionException("非草稿状态的产品不允许关联分公司!");
                        }
                    }
                    if (entityRelationShip.SchemaName == "ubg_product_ubg_datalist")//产品与资料列表N:N的关联
                    {
                        EntityReference TargetEntity = (EntityReference)context.InputParameters["Target"];
                        Entity product = service.Retrieve(TargetEntity.LogicalName, TargetEntity.Id, new ColumnSet("ubg_approvestate"));
                        if (product.Attributes.Contains("ubg_approvestate") && ((OptionSetValue)product["ubg_approvestate"]).Value != 1)
                        {
                            throw new InvalidPluginExecutionException("非草稿状态的产品不允许资料!");
                        }
                    }
                }
            }


        为了方便那些确实没办法访问wordpress的,我这里把注册的图也给贴出来


  • 相关阅读:
    python3 生成器&迭代器
    python3 装饰器
    python3 函数的形参、实参、位置参数、默认参数、关键字参数以及函数的递归
    python3 对文件的查找、替换、删除
    python3 字典相关函数
    python3 字符串相关函数
    spring定时任务-文件上传进度条
    linux系统下开发环境安装与配置
    java中的逃逸分析
    elastic
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6205807.html
Copyright © 2011-2022 走看看