首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CRM 2011 -插件-联系人禁用事件

CRM 2011 -插件-联系人禁用事件
EN

Stack Overflow用户
提问于 2013-10-25 07:49:01
回答 1查看 488关注 0票数 0

我试图为客户关系管理2011插件,将更新一些价值在一个联系实体时,它已被禁用。

当联系人被禁用时:我希望它将3个单选按钮更改为"Nei“(挪威文为No)。这将禁用对我为客户提供的自助服务门户的访问。您可以看到我的联系人实体的图片和单选按钮在其中这里。当联系人被禁用时,我想强制所有这些单选按钮到"Nei“。

我是一个完全初学者的客户关系管理插件开发,并相当新的用户C#。所以请尽量简单。

几个星期来,我一直在阅读手册,似乎什么也做不了。(嗯,微软并不以他们写得很好的手册而闻名)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-25 08:19:44

您需要将插件注册到SetStateSetStateDynamicEntity消息,以Pre-Operation作为执行阶段。以这段代码为例:

代码语言:javascript
复制
using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace TestPlugin
{
    public class UpdateBoolFields : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            try
            {
                if (context.InputParameters.Contains("EntityMoniker") &&
                   context.InputParameters["EntityMoniker"] is EntityReference)
                {
                    EntityReference targetEntity = (EntityReference)context.InputParameters["EntityMoniker"];
                    OptionSetValue state = (OptionSetValue)context.InputParameters["State"];
                    if (state.Value == 1)// I'm not sure is 1 for deactivate
                    {
                        IOrganizationService service = factory.CreateOrganizationService(context.UserId);
                        Entity contact = service.Retrieve(targetEntity.LogicalName, targetEntity.Id, new ColumnSet(true));
                        contact["field1"] = false;
                        contact["field2"] = false;
                        contact["field3"] = false;
                        service.Update(contact);
                    }
                }

            }
            catch (Exception e)
            {
                throw new InvalidPluginExecutionException(e.Message);
            }
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19584116

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档