0
我想在特定字段正在更新时触发插件。CRM插件调用字段更新调用WCF
这里是我打电话
public class CaseStageUpdate : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
try
{
// Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
if (serviceProvider == null)
{
throw new ArgumentNullException("serviceProvider");
}
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
Entity entity;
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
string strParams = "None";
entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "entityname")
{
// Create Matter Process
try
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
if (entity.Attributes.ContainsKey("field")){// call web service}
}
catch (Exception ex)
{
tracingService.Trace("Plugin Exception : \n {0}", ex.ToString());
throw;
}
}
catch (Exception ex)
{
tracingService.Trace("Plugin Exception : \n {0}", ex.ToString());
throw;
}
}
}
else
{
throw new InvalidPluginExecutionException("Plugin is not valid for this enity.");
}
}
catch (Exception ex)
{
}
}
}
在我更新实体WCF的代码,但插件再次呼吁,因为更新的领域在插件再次发现。但我没有更新该领域。
假设我想更新AAA字段更新的ABC字段。我触发设置AAA字段时,我会更新ABC字段。
WCF代码
Entity entity = service.Retrieve("entityname", Guid.Parse(Id), new ColumnSet(true));
entity.Attributes["ABC"] = "TEST";
service.Update(entity);
重新阅读您的问题后,我对您的实际问题有点困惑。你是否试图从WCF服务中更新实体,并导致插件再次启动? – Daryl