【问题标题】:MS CRM 2015, plugins don't seem to fireMS CRM 2015,插件似乎没有触发
【发布时间】:2015-01-12 11:23:59
【问题描述】:

我在使用新的 MS CRM 2015 时遇到了一些问题,因为我无法启动我的插件。 我什至尝试从 2015 SDK 中提取一些非常简单的插件示例并将它们注册为“非沙盒”,但结果是一样的。

在触发事件上我实际上无法做任何事情的是插件分析器,但这对我并没有太大帮助。

有其他人遇到过这个问题吗?

我真的可以就下一步尝试/检查什么提供一些建议,因为在这种情况下 Google 似乎不是我的朋友?

顺便说一下,当前部署是本地部署,但服务器上没有可用的 Visual Studio。

这里是示例中的代码,我对它进行了一点改动,只在 1 个特定帐户上触发。

using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;

namespace Microsoft.Crm.Sdk.Samples
{
    public class FollowupPlugin: IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            //</snippetFollowupPlugin1>

            //<snippetFollowupPlugin2>
            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                // Obtain the target entity from the input parameters.
                Entity entity = (Entity)context.InputParameters["Target"];
                //</snippetFollowupPlugin2>

                // Verify that the target entity represents an account.
                // If not, this plug-in was not registered correctly.
                if (entity.LogicalName != "account")
                    return;

                try
                {
                    if (entity.Attributes.ContainsKey("accountid"))
                    {
                        if (entity.GetAttributeValue<Guid>("accountid").ToString().ToLower() == "ee03d883-5b18-de11-a0d1-000c2962895d") // specific test account
                        {
                            // Create a task activity to follow up with the account customer in 7 days. 
                            Entity followup = new Entity("task");

                            followup["subject"] = "Send e-mail to the new customer.";
                            followup["description"] = "Follow up with the customer. Check if there are any new issues that need resolution.";
                            followup["scheduledstart"] = DateTime.Now.AddDays(7);
                            followup["scheduledend"] = DateTime.Now.AddDays(7);
                            followup["category"] = context.PrimaryEntityName;

                            // Refer to the account in the task activity.
                            if (context.OutputParameters.Contains("id"))
                            {
                                Guid regardingobjectid = new Guid(context.OutputParameters["id"].ToString());
                                string regardingobjectidType = "account";

                                followup["regardingobjectid"] = new EntityReference(regardingobjectidType, regardingobjectid);
                            }

                            //<snippetFollowupPlugin4>
                            // Obtain the organization service reference.
                            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                            //</snippetFollowupPlugin4>

                            // Create the task in Microsoft Dynamics CRM.
                            tracingService.Trace("FollowupPlugin: Creating the task activity.");
                            service.Create(followup);
                        }
                    }
                }
                //<snippetFollowupPlugin3>
                catch (FaultException<OrganizationServiceFault> ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in the FollupupPlugin plug-in.", ex);
                }
                //</snippetFollowupPlugin3>

                catch (Exception ex)
                {
                    tracingService.Trace("FollowupPlugin: {0}", ex.ToString());
                    throw;
                }
            }
        }
    }
}

注册截图:

【问题讨论】:

  • 我仍然无法让它为更新事件工作,但删除了对 accountid 的检查,我现在可以让它为 create 事件触发,这是一个阶梯。

标签: plugins dynamics-crm dynamics-crm-2015


【解决方案1】:

尝试使用以下代码:

using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
namespace Microsoft.Crm.Sdk.Samples
{
    public class FollowupPlugin: IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            //</snippetFollowupPlugin1>

            //<snippetFollowupPlugin2>
            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                // Obtain the target entity from the input parameters.
                Entity entity = (Entity)context.InputParameters["Target"];
                //</snippetFollowupPlugin2>

                // Verify that the target entity represents an account.
                // If not, this plug-in was not registered correctly.
                if (entity.LogicalName != "account")
                    return;

                try
                {

                        if (entity.Id.Equals(new Guid("ee03d883-5b18-de11-a0d1-000c2962895d")) // specific test account
                        {
                            // Create a task activity to follow up with the account customer in 7 days. 
                            Entity followup = new Entity("task");

                            followup["subject"] = "Send e-mail to the new customer.";
                            followup["description"] = "Follow up with the customer. Check if there are any new issues that need resolution.";
                            followup["scheduledstart"] = DateTime.Now.AddDays(7);
                            followup["scheduledend"] = DateTime.Now.AddDays(7);
                            followup["category"] = context.PrimaryEntityName;
                            followup["regardingobjectid"] = entity.ToEntityReference();

                            //<snippetFollowupPlugin4>
                            // Obtain the organization service reference.
                            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                            //</snippetFollowupPlugin4>

                            // Create the task in Microsoft Dynamics CRM.
                            tracingService.Trace("FollowupPlugin: Creating the task activity.");
                            service.Create(followup);
                        }
                }
                //<snippetFollowupPlugin3>
                catch (FaultException<OrganizationServiceFault> ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in the FollupupPlugin plug-in.", ex);
                }
                //</snippetFollowupPlugin3>

                catch (Exception ex)
                {
                    tracingService.Trace("FollowupPlugin: {0}", ex.ToString());
                    throw;
                }
            }
        }
    }
}

【讨论】:

  • 我也不确定原始插件代码是为创建事件而不是更新事件编写的事实是否会导致它不触发。
  • 根据您的屏幕截图,我假设您已经针对更新事件注册了插件。所以现在代码应该可以正常工作了。
  • 如果不检查任何帐户ID,它就可以在创建时工作,所以它现在做了它应该做的事情,但不确定有什么不同是/应该是代码明智的,如果它是更新而不是创建.
  • 我现在确实让它工作了,但我不确定我到底做了什么让它工作,因为我因为匆忙尝试了很多不同的东西。它现在工作了- 感谢您花时间帮助我。
猜你喜欢
  • 2012-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多