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的,我这里把注册的图也给贴出来


  • 相关阅读:
    FFmpegTool 这个是很早以前写得ffmpeg c99部分转C89工具代码
    mmsplayer V2 for IOS 完成. V2 所有汇总
    关于mmsplayer一些电台不支持播放问题说明
    libmpg123 解码库用法
    [置顶] mmsplayer V2 for IOS 完成. V2 所有汇总
    使用lipo合并iPhone模拟器和真机的静态类库
    vbs编程
    Adobe reader查阅PDF文件无法显示中文
    常去的下载网站
    .Net程序设计快速入门——分页设计篇
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6205807.html
Copyright © 2011-2022 走看看