CRM动态插件更新不工作
本文关键字:工作 更新 插件 动态 CRM | 更新日期: 2023-09-27 18:04:00
我有一个CRM Dynamics插件,在布尔值更改的更新上触发,当我在两个选项控件上选择是时,它无法触发,请在下面找到我的代码并建议我可能出错的地方。
namespace WebCall.Plugin
{
public class WebCallTrigger : IPlugin
{
/// <summary>
/// Plugin to initiate a web call from CRM using MaruSip API
/// </summary>
/// <param name="serviceProvider"></param>
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context == null)
{
throw new ArgumentNullException("localContext");
}
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
//initaialize Entity
Entity phoneCallEntity = (Entity)context.InputParameters["Target"];
if (phoneCallEntity.LogicalName != Contact.EntityLogicalName)
return;
//ensure that the Plugin fires on a create operaton
if (context.MessageName == "Update")
{
try
{
if (phoneCallEntity.Attributes.Contains("new_dialnumber"))
phoneCallEntity["new_dialnumber"] = true;
string NumberToCall; // = phoneCallEntity.Contains("telephone1") ? phoneCallEntity["telephone1"].ToString() : null;
if (phoneCallEntity.Contains("telephone1"))
{
NumberToCall = phoneCallEntity.Attributes["telephone1"].ToString();
}
else
{
NumberToCall = phoneCallEntity.Attributes["mobilephone"].ToString();
}
string ReceiveCallOn = phoneCallEntity.Contains("new_receivecallon") ? phoneCallEntity["new_receivecallon"].ToString() : null;
string apiKey = phoneCallEntity.Attributes.Contains("new_apikey") ? phoneCallEntity.Attributes["new_apikey"].ToString() : null;
int fId = phoneCallEntity.Attributes.Contains("new_fid") ? (int)phoneCallEntity.Attributes["new_fid"] : 0;
//service.Update(phoneCallEntity);
//Create a new instance of the WebCallService and call the webcall method
WebCallService webCallService = new WebCallService();
webCallService.WebCall(NumberToCall, ReceiveCallOn, apiKey, fId);
}
如果telephone1或mobilphone字段没有更新-您引用的目标将不包含提到的字段。我的建议是从预图像中获取数据。您可以查看这篇文章- https://deepakexploring.wordpress.com/2011/02/04/preentityimages-and-postentityimages-in-crm-5-0-2011/
如果您在更新电话呼叫实体时注册了插件,并且您将其逻辑名称与"Contact"进行比较,则插件将永远不会触发。
从您的代码中查看这一行:
if (phoneCallEntity.LogicalName != Contact.EntityLogicalName)
return;