【问题标题】:CRM 2011 - Plugin - Contact disabled eventCRM 2011 - 插件 - 联系人禁用事件
【发布时间】:2023-03-11 20:22:01
【问题描述】:

我正在尝试为 CRM 2011 制作一个插件,当它被禁用时,它将更新联系人实体中的一些值。

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

我是 CRM 插件开发的完全初学者,也是 C# 的新用户。所以请尽量保持简单。

我已经阅读手册好几个星期了,但我似乎无处可去。 (嗯,微软并不以其写得很好的手册而闻名)。

【问题讨论】:

  • 我回答了你的问题。有一件事:如果你说“微软不以其写得好的手册而闻名”,至少向我们展示你的陈述的一些证据,否则是对所有在 MSDN Library 工作(和工作)的人的侮辱。
  • @GuidoPreite 非常感谢!我并不是说 ALL MSDN 文档不好。我要说的是他们中的一些人可以做更多的工作。我可以以this 为例。该文档并不能真正帮助像我这样的初学者了解那里发生的事情。并且基于条目的评级:它对许多其他用途也没有帮助......我不打算在 StackOverflow 上进一步讨论这个问题。

标签: c# plugins dynamics-crm-2011


【解决方案1】:

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

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);
            }
        }
    }
}

【讨论】:

  • 正是我想要的!非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多