我试图为客户关系管理2011插件,将更新一些价值在一个联系实体时,它已被禁用。
当联系人被禁用时:我希望它将3个单选按钮更改为"Nei“(挪威文为No)。这将禁用对我为客户提供的自助服务门户的访问。您可以看到我的联系人实体的图片和单选按钮在其中这里。当联系人被禁用时,我想强制所有这些单选按钮到"Nei“。
我是一个完全初学者的客户关系管理插件开发,并相当新的用户C#。所以请尽量简单。
几个星期来,我一直在阅读手册,似乎什么也做不了。(嗯,微软并不以他们写得很好的手册而闻名)。
发布于 2013-10-25 08:19:44
您需要将插件注册到SetState和SetStateDynamicEntity消息,以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);
}
}
}
}https://stackoverflow.com/questions/19584116
复制相似问题