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