0

I'm having some trouble with the new MS CRM 2015 as I cannot make my plugins fire. I even tried to take some of the very simple plugin samples from the 2015 SDK and register them 'non sandbox' but the result is the same.

The only thing I cant actually get to do anything on the triggering event is the plugin profiler, but that doesn't really help me much.

Has anyone else had this problem?

I could really use some advice on what to try/check next because Google doesn't appear to be my friend in this case?

The current deployment is on-premise by the way but there is no Visual Studio available on the server.

Here is the code from sample which I have altered just a tiny bit to only trigger on 1 specific account.

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;
                }
            }
        }
    }
}

Registration screenshots:

enter image description here enter image description here

Aidal
  • 799
  • 4
  • 8
  • 33
  • I still can't make it work for the update event but removing the check for accountid, I can now make it fire for the create event, which is a step up the ladder. – Aidal Jan 12 '15 at 12:39

1 Answers1

1

Try to use following code:

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;
                }
            }
        }
    }
}
Siddique Mahsud
  • 1,453
  • 11
  • 21
Andrew Butenko
  • 5,048
  • 1
  • 14
  • 13
  • I'm also not sure if the fact that the original plugin code was made for the create event and not the update event, could cause it not to fire. – Aidal Jan 12 '15 at 12:24
  • Based on your screenshot I assume that you've registered plugin against Update event. So now code should work fine. – Andrew Butenko Jan 12 '15 at 12:39
  • It works on create if not checking for any accountid, so it now does what it is supposed to, though not sure what the different is/should be code wise had it been an update and not a create. – Aidal Jan 12 '15 at 12:41
  • I actually made it work now, but I'm not sure what exactly it was I did to make it work as I tried so many different things due to the rush I was in. It works now though - thanks for taking time to help me out though. – Aidal Jan 13 '15 at 07:17