locked
Plugin to deactivate an Account - CRM 2011 RRS feed

  • Question

  • I am converting CRM 4.0 code to CRM 2011. Part of the plugin is to close all related Opportunities when an Account is deactivated. For this I have 'SetState' and 'SetStateDynamicEntity' Messages registered both on Post-Operation. But I could not pass the following if condition.

    if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference)

    {

              CloseOpportunities();

    }

    When Deactivate button on the form is pressed I see the InputParameters contains "Target" but not "EntityMoniker". What am I missing here?


    • Edited by shiil Friday, May 11, 2012 3:06 AM
    Friday, May 11, 2012 3:05 AM

Answers

  • Shil,

    The Target InputParameters is merely a way for CRM to pass in the updated entity into your plugin. This Target parameter will get populated automatically by CRM in almost all plugin messages.

    So to answer your question, if you don't want to use Target, you could register Post Image on both SetState and SetStateDynamicEntity message.

    From inside your code, you will do something like this.

    if (context.PostEntityImages.Contains("PostImage"))
    {
       var postImage = context.PostEntityImages["PostImage"];
       
       if (postImage.Contains("statecode"))
       {
          // Check if statecode is inactive and close opportunity if statecode is inactive
          
       }
    }

    Hope this helps.


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

    Tuesday, May 15, 2012 1:08 AM

All replies

  • Hi Shil,

    EntityMoniker is deprecated in CRM 2011.

    You should be able to use the "Target" and make sure you convert it to Entity class.

    Eg: ((Microsoft.Xrm.Sdk.Entity) context.InputParameters["Target"])

    I hope this helps. If my response answered your question, please mark the response as an answer.


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

    Friday, May 11, 2012 3:43 AM
  • Hi,  I couldn't use "Target" InputParameters as the InputParameters contain "Target" even for "update" message. I am already doing something else on Update. Is there any other condition I need to check for Account deactivation?
    Tuesday, May 15, 2012 12:42 AM
  • Shil,

    The Target InputParameters is merely a way for CRM to pass in the updated entity into your plugin. This Target parameter will get populated automatically by CRM in almost all plugin messages.

    So to answer your question, if you don't want to use Target, you could register Post Image on both SetState and SetStateDynamicEntity message.

    From inside your code, you will do something like this.

    if (context.PostEntityImages.Contains("PostImage"))
    {
       var postImage = context.PostEntityImages["PostImage"];
       
       if (postImage.Contains("statecode"))
       {
          // Check if statecode is inactive and close opportunity if statecode is inactive
          
       }
    }

    Hope this helps.


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

    Tuesday, May 15, 2012 1:08 AM