locked
Dont want to deactivate an account when oppurtunity status is open. RRS feed

  • Question

  • Hi, I got a requrement , if account having oppurtunity and if the oppurtunity having status as open then user should not be able to deactivate the account record.

    Please help me through this issue.

    Thank you.

    Tuesday, November 14, 2017 12:50 PM

All replies

  • Hi Krish,

    It is not possible OOB. But you can write a plugin on SetStateDynamic of Account and then restrict the deactivation if any open Opportunity related to the account found.

    Hope this helps.

    Sid

    • Proposed as answer by MGCRM Saturday, November 18, 2017 8:58 PM
    Tuesday, November 14, 2017 2:26 PM
  • Hi,

    use plugin on account status change. If account has open opportunity reactive account.


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Wednesday, November 15, 2017 6:00 AM
  • Hello, 

    you can use the below code in your plugin - and register the plugin on both SetState and SetStatedynamicEntity as two different steps.

    "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                                          <entity name='opportunity'>
                                                            <attribute name='opportunityid' />
                                                            <filter type='and'>
                                                              <condition attribute='statecode' operator='eq' value='0' />
                                                              <condition attribute='parentaccountid' operator='eq' value='[account_GUID]' />
                                                            </filter>
                                                          </entity>
                                                        </fetch>";
    
                EntityCollection openOpportunity_count_result = _service.RetrieveMultiple(new FetchExpression(openOpportunity_count));
    
                if (openOpportunity_count_result.Entities.Count > 0)
                {
                    throw new InvalidPluginExecutionException("The account cannot be deactivated because there are open Opportunities against it.");
                }


    Thanks and Regards.

    Tuesday, December 5, 2017 8:35 AM