How to set completion date when Appointment 'Mark Complete' clicked

Unanswered How to set completion date when Appointment 'Mark Complete' clicked

  • Wednesday, May 16, 2012 5:24 PM
     
      Has Code

    Hi

    I am trying to write a plugin to set completion date on appointment when 'Mark Complete' is clicked from Ribbon. I registered the plugin on pre stage for the messages setState and setStateDynamicEntity but unfortunately i never get the updated status for me to check if activity is completed before i could set the completion date in a custom field.

    However if i try to click the "Close Appointment" button and then in dialog box select "Completed" , only then code works.

    Any idea why it is not working with "Mark Complete" button?

    following is the code i am trying to use on pre stage :

    try
                {
    
    
                    if (context.InputParameters.Contains("EntityMoniker") &&
                            context.InputParameters["EntityMoniker"] is EntityReference)
                {
                        tracerService.Trace("Set Diarynote completion plugin initialized");
    
                        int statusCode = ((OptionSetValue)context.InputParameters["Status"]).Value;
    
    
                            if (statusCode == 3) //3=completed
                            {
    
          Entity    appointment=new Entity("appointment");
        appointment["cq_completiondate"] = DateTime.UtcNow;
        xrmService.Update(appointment);
                            }
    
    
                    }//end outer most if
                } //end try
                

    Thanks

    Umer

All Replies

  • Wednesday, May 16, 2012 5:35 PM
    Moderator
     
     

    why dont you check on the "statecode" field instead of the status code:

    int stateCode = ((OptionSetValue)context.InputParameters["State"]).Value;

    Then you can cover in the same plugin all the statuses for the closed activity.


    Gonzalo | gonzaloruizcrm.blogspot.com

  • Wednesday, May 16, 2012 5:38 PM
     
     

    Hi

    i have done that as well but no luck. Interestingly i get the correct statuses if i click "Mark Complete" and plugin is Registered for post event  not pre which is not the solution as on post record becomes read only and i cannot set completion date any more.

    I can understand that "Mark Complete" is a generic button for all activities type but still it should fulfil the purpose and give me the correct status value as i get when clicking "Close Appointment".

    An more ideas please.?

  • Wednesday, May 16, 2012 11:34 PM
     
     

    Umer, 

    What version of CRM is this plugin running on?

    Cheers.


    Dimaz Pramudya - CRM Developer - CSG (Melbourne) www.xrmbits.com http://twitter.com/xrmbits

  • Thursday, May 17, 2012 11:16 AM
     
      Has Code

    Hi,

    Entity   appointment=new Entity("appointment");
    appointment["cq_completiondate"] = DateTime.UtcNow;
    xrmService.Update(appointment);

    Is not the right way to update field in pre-stage.
    You need to change the value inside the context entity.

    Try something like:

    // Obtain the target business entity from the input parmameters.
    entity = (DynamicEntity)context.InputParameters.Properties["Target"];
    appointment["cq_completiondate"] = DateTime.UtcNow;


    Yair Rozenberg

  • Thursday, May 17, 2012 12:07 PM
    Moderator
     
     

    If you do it with statecode, in the pre-operation, what is the value of statecode here:

    int stateCode = ((OptionSetValue)context.InputParameters["State"]).Value;


    Gonzalo | gonzaloruizcrm.blogspot.com

  • Saturday, May 19, 2012 9:32 PM
     
     

    Statecode is 1 and even if i click 'Mark Complete' it still shows 1 on pre.

  • Saturday, May 19, 2012 9:35 PM
     
     

    Hi

    At the moment updating is not an issue as i explained before with 'Mark Complete' button i am not able to get the updated status value for 'Completed' and always get 1 which is not helping me to decide whether to set the completion date. And also as explained before same code works when 'Close Appointment' button is clicked and plugin is as usual registered for pre stage. Then i do get value 3=complete.

    Umer

  • Saturday, May 19, 2012 9:35 PM
     
     

    Hi

    CRM 2011 on Premise.

    Umer