繁体   English   中英

CRM Dynamics插件更新无法正常工作?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM