您的位置:首页 > 其它

crm插件简单例子--给实体中的字段赋值

2017-07-27 17:29 246 查看
 public void Execute(IServiceProvider serviceProvider)

        {

            //用于调试的沙盒插件追踪服务

            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            // 从服务提供者获取执行上下文。

            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            // 输入参数的集合包含所有的数据请求消息传递。

            if (context.InputParameters.Contains("Target") &&context.InputParameters["Target"] is Entity)

            {

                //从输入参数得到目标实体。

                Entity entity = (Entity)context.InputParameters["Target"];

                // 验证目标实体是否代表帐户.

                // 如果没有,则此插件没有正确注册。.

                if (entity.LogicalName != "lead")

                    return;

                try

                {

                    //Entity 实体

                    //给目标实体的字段赋值

                    entity["new_autonumber"] = "112";

                    //创建一个实体对象

                    //Entity opportunity = new Entity();

                }

                catch (Exception)

                {

                    throw;

                 }

                }

            }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: