[英]CRM Dynamics Plugin on Update not Working?
我有一個CRM動態插件,它會在布爾更改的更新時啟動,當我在“兩個選項”控件上選擇“是”時,它將無法啟動,請在下面找到我的代碼並提出可能會出錯的建議。
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);
}
如果phone1或mobilephone字段未更新-您所指的目標將不包含提及的字段。 我的建議是從pre-Image獲取該數據。 您可以查看這篇文章-https://deepakexploring.wordpress.com/2011/02/04/preentityimages-and-postentityimages-in-crm-5-0-2011/
如果您在電話實體更新時注冊了該插件,並且將其邏輯名稱與“聯系”進行比較,則該插件將永遠不會觸發。
查看您代碼中的這一行:
if (phoneCallEntity.LogicalName != Contact.EntityLogicalName)
return;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.