locked
Post Create Plugin is not firing RRS feed

  • Question

  • Hi,

    Can anybody help me,

    I have created a plugin and registerd on Post Create of serviceappointment entity and updating a custom attribute new_workflowrundate.
    It got registered successfully. But after creating the serviceactivity the custom attribute is not updating.

    Note: The code in the plugin worked fine in the Aspx page which i placed for testing, but not working after registering plugin.


    Below is the Code for the plugin

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.SdkTypeProxy;


    namespace RunWorkflowPlugin
    {
        public  class ActivityUpdate:IPlugin
        {
            public void Execute(IPluginExecutionContext context)
            {
               
                DateTime dt = DateTime.Now;
                if (dt.DayOfWeek == DayOfWeek.Monday)
                    dt = dt.AddDays(3);
                else
                    dt = dt.AddDays(1);
            
                //update the Service Activity
                //Make sure we have an entity to work with

                if (context.InputParameters.Properties.Contains("Target") && context.InputParameters.Properties["Target"] is DynamicEntity)
                {
                    //Get the current service activity details
                    Guid activityID = new Guid(context.OutputParameters.Properties["id"].ToString());

                   
                    ICrmService service = context.CreateCrmService(true);
                   
                    //Obtain Guid

                    TargetRetrieveDynamic trd = new TargetRetrieveDynamic();
                    trd.EntityId = activityID;
                    trd.EntityName = "serviceappointment";

                    //Retrieve Request

                    RetrieveRequest rr = new RetrieveRequest();
                    //Get the Columnset
                    rr.ColumnSet = new Microsoft.Crm.Sdk.Query.AllColumns();
                    rr.ReturnDynamicEntities = true;
                    rr.Target = trd;

                    //Retrieve Response

                    RetrieveResponse rs = (RetrieveResponse)service.Execute(rr);

                    DynamicEntity entity = (DynamicEntity)rs.BusinessEntity;
                    CrmDateTime crmDate = new CrmDateTime();
                    crmDate.Value = dt.ToString("s");     // s = "UTC format"

                    (entity.Properties["new_workflowrundate"]) = crmDate;
                    //(entity.Properties["new_workorder"]) = "workorder123";
                                               
                    service.Update(entity);

                }


            }
        }
    }


    Please suggest me if any thing needs to be changed in the code


    Thanks and Regards,
    Mohammad.Riyazuddin
    CRM Consultant


    Mohammad Riyazuddin CRM Consultant
    Monday, September 28, 2009 12:37 PM

Answers

  • I answered it (I think, but maybe not) in the other post you opened...
    My blog : http://mscrmtools.blogspot.com You will find: Form Javascript Manager (export/import javascript from forms) ISV.Config Manager (graphical ISV.config edition - export/import) View Layout replicator (customize one view and replicate to others) And others (use tool tag on my blog)
    Tuesday, September 29, 2009 1:34 PM
    Moderator

All replies

  • Hi,

    I'm not sure but I think that this line is incorrect :

    (entity.Properties["new_workflowrundate"]) = crmDate;

    Because the "new_workflowrundate" has never been added to the DynamicEntity, you should write:

     DynamicEntity entity = (DynamicEntity)rs.BusinessEntity;
     CrmDateTime crmDate = new CrmDateTime();
     crmDate.Value = dt.ToString("s");     // s = "UTC format"
     CrmDateTimeProperty dtp = new CrmDateTimeProperty();
     dtp.name = "new_workflowrundate";
     dtp.Value = crmDate;
     entity.Properties.Add(dtp);

    More over, this operation, you try to do, should be done in preEvent, adding the property directly to the DynamicEntity instead of doing it in postEvent and updating again the entity.

    Monday, September 28, 2009 12:45 PM
    Moderator
  • Hi,

    First, I would suggest enabling tracing in order to see whether the code from the plugin is executed at all and what is the error (here are the steps that will guide you through the process of enabling the trace: http://support.microsoft.com/kb/907490/en-us). Only then you may try to debug the plugin. You said that this code worked when invoked from your custom aspx page. Have you signed the assembly with a key when you created a plugin? The assembly may still not be signed and therefore the code is not even executed.

    Best regards,
    Kuba
    -- Kuba Skałbania, Netwise
    Monday, September 28, 2009 2:00 PM
  • Thanks for your reply Kuba,

    I have signed the assemply, and registerd the plugin on Post Create of the Service Appointment entity.

    Regards,
    Mohammad Riyazuddin.
    CRM Consultnat.
    Mohammad Riyazuddin CRM Consultant
    Monday, September 28, 2009 2:04 PM
  • Try to debug the plugin. Step into the code and verify what causes the error. In order to debug the plugin you should deploy it to the hard drive (not to the database). Remember to copy the dll and pdb files to the bin\assembly folder of your CRM installation.
    Once you copy the files and register the plugin, start your Visual Studio and attach to the w3wp.exe process (to your CRM) and debug the code.

    I hope that helps,
    Kuba
    -- Kuba Skałbania, Netwise
    Monday, September 28, 2009 10:37 PM
  • Hi Kuba,

    I have deployed the Plugin in the Disk and copied the dll and pdb files to the bin\assembly folder of the CRM installation and attached  the W3wp.exe process
    and in visual studio inserted break points and in CRM created on Service Activity, but i am unable to Debug the plugin code.

    It means plugin is not executing on Post Create of the Service Activity.

    Please Can you suggest me what will be the problem.

    Thanks and Regards,
    Mohammad.Riyazuddin.
    Mohammad Riyazuddin CRM Consultant
    Tuesday, September 29, 2009 6:06 AM
  • If the plugin is registered on disk you need to do the iisreset to redeploy - an alternative is to register it in the database, in which case you can just update the assembly registration.
    see this
    http://msdn.microsoft.com/en-us/library/cc151088.aspx
    Tuesday, September 29, 2009 6:10 AM
  • Hi Muhammad Ali,

    I have tried a lot but the plugin on create of serviceappointmet is not working. I have applied the same logic to update the lead,account entities they got updated on postcreate but serviceappointment is not updating.

    Note : Even i have tried to register the serviceappointment plugin  Trigger as a ChildPipeline. if i do so i am getting an error called "An error occured" as a dialog box. if i click on ok and click on save i am getting another error as scheduling engine error.

    Please help me.

    Thanks and Regards,
    Mohammad.Riyazuddin.
    CRM Consultant.
    Mohammad Riyazuddin CRM Consultant
    Tuesday, September 29, 2009 1:24 PM
  • I answered it (I think, but maybe not) in the other post you opened...
    My blog : http://mscrmtools.blogspot.com You will find: Form Javascript Manager (export/import javascript from forms) ISV.Config Manager (graphical ISV.config edition - export/import) View Layout replicator (customize one view and replicate to others) And others (use tool tag on my blog)
    Tuesday, September 29, 2009 1:34 PM
    Moderator