I have a CRM Dynamics plugin that fires on an Update of a boolean change, it fails to fire when I select Yes on the Two Option control, Please find my code below and advice where I may be going wrong.
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);
}