zoukankan      html  css  js  c++  java
  • Dynamics 365 CE在Pre Delete插件中应用Image

    微软动态CRM专家罗勇 ,回复327或者20190428可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!

    在插件中限制记录的删除是常见的场景,比如根据statuscode的状态来限制删除。

    这时候在实体的Delete消息的Pre Operation阶段注册一个插件,并注册一个Image,我这里类似如下:

     

    然后我这里使用插件代码类似如下:

    using Microsoft.Xrm.Sdk;
    using System;
    
    namespace Plugins
    {
        public class PreMyEntityDelete : IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                if(context.PreEntityImages.Contains("PreImg"))
                {
                    var statuscodeField = context.PreEntityImages["PreImg"].GetAttributeValue<OptionSetValue>("statuscode");
                    if(statuscodeField.Value != 1 && statuscodeField.Value != 2)
                    {
                        throw new InvalidPluginExecutionException("Only draft or inactive request can be deleted!");
                    }
                }
                else
                {
                    throw new InvalidPluginExecutionException("Pre delete image - PreImg does not exist!");
                }
            }
        }
    }
  • 相关阅读:
    经典SQL语句大全 学者必看
    13个SQL优化技巧
    全面解析SQL SERVER 的左右内连接
    ORM框架
    JPA SQL 的复杂查询createNamedQuery
    SQL 复杂查询
    前端学习(十三)js运算符(笔记)
    前端学习(十二)js数据类型(笔记)
    前端学习(十一)函数(笔记)
    前端学习(十)初识js(笔记)
  • 原文地址:https://www.cnblogs.com/luoyong0201/p/Dynamics_365_Delete_Plugin_Image.html
Copyright © 2011-2022 走看看