locked
CRM 2011 - Show a warning message when a record is being deactivated RRS feed

  • Question

  • Hi,

    I need to show a warning to the user if a record is being deactivated. There's a catch : I need to show the warning only IF the current record is associated with another record. (For example, I'm deactivating a Contact record which is already associated with an Active Account. )

    Here are my challenges :

    1. I do not have the lookup field on my child entity form. So first I need to retrieve the lookup id that's not on the form.

    2. I need to retrieve the parent entity record based on the id, and determine it's status.

    3. If the parent record is Active I need to show the warning.

    I have no idea where/how to start. Please help.

    Thanks in advance.


    Thursday, September 29, 2011 5:06 AM

Answers

  • Hi,

    You can develop a plugin (http://msdn.microsoft.com/en-us/library/gg695782.aspx#Y3313) register it on Pre-Operation stage on SetStateDynamicEntity message for Contact entity and in plugin code you can check if the parent account status is active then abort execution and throw exception. You may refer the sample code below:

    // Check if User Has Performed Record Deactivated Action (for entity Account)

    if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference &&
    ((EntityReference)context.InputParameters["EntityMoniker"]).LogicalName == "contact") {
    switch (context.MessageName)
    {

    case "SetStateDynamicEntity":

    if (context.InputParameters.Contains("Status"))
    {

    // Check if User has requested to Published Article
    if (((OptionSetValue)context.InputParameters["Status"]).Value == 1)
    {
        Entity AccountEntity= CrmService.Retrieve("account",accountid, new ColumnSet(new string[]{"statecode"}) );

        if ( ((OptionSetValue)AccountEntity["statecode"]).Value == 0)

        {

                throw new InvalidPluginExecutionException("You can not disable contact if parent account is activated.");

        }


     }
    }
    }


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Thursday, September 29, 2011 6:23 AM

All replies

  • Hi,

    You can develop a plugin (http://msdn.microsoft.com/en-us/library/gg695782.aspx#Y3313) register it on Pre-Operation stage on SetStateDynamicEntity message for Contact entity and in plugin code you can check if the parent account status is active then abort execution and throw exception. You may refer the sample code below:

    // Check if User Has Performed Record Deactivated Action (for entity Account)

    if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference &&
    ((EntityReference)context.InputParameters["EntityMoniker"]).LogicalName == "contact") {
    switch (context.MessageName)
    {

    case "SetStateDynamicEntity":

    if (context.InputParameters.Contains("Status"))
    {

    // Check if User has requested to Published Article
    if (((OptionSetValue)context.InputParameters["Status"]).Value == 1)
    {
        Entity AccountEntity= CrmService.Retrieve("account",accountid, new ColumnSet(new string[]{"statecode"}) );

        if ( ((OptionSetValue)AccountEntity["statecode"]).Value == 0)

        {

                throw new InvalidPluginExecutionException("You can not disable contact if parent account is activated.");

        }


     }
    }
    }


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Thursday, September 29, 2011 6:23 AM
  • There are few option

             Download the sdk there are few samples in it.

           also hide the existing deactivate button.

    • You can overwrite the command definition of the existing button by adding custom action to the entity ribbon.

    here is link about how to do different things to ribbon. This is not exactly for your issue but it will give a stating point to play with ribbon customizations.

     

    I hope this helps.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Proposed as answer by Amreek Singh Thursday, September 29, 2011 6:25 AM
    Thursday, September 29, 2011 6:24 AM
  • Thank you Javeed and Amreek. I think I'll go with the Plugin option for now, I want to do it the Javascript way but it looks like a lengthy process.
    Friday, September 30, 2011 10:54 AM
  • HI Rajesh,

    If you find any the reply useful then Please Mark as Asnwer.


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Friday, September 30, 2011 11:38 AM