locked
Disable Business Unit Using C# Dynamics CRM 2013 RRS feed

  • Question

  • Hi All

    I am trying to disable Business Unit but unable to do that.
    Following is the code sample I am using to disable Business Unit.

                    BusinessUnit bu = OrganizationService.Retrieve(BusinessUnit.EntityLogicalName,
                              BusinessUnitID, new ColumnSet(new String[] { "name", "businessunitid", "parentbusinessunitid", "isdisabled" })).ToEntity<BusinessUnit>();
                    OptionSetValue state = new OptionSetValue(1);
    
                    OptionSetValue status = new OrganizationSetValue(2);
    
    
                        SetStateRequest request = new SetStateRequest()
                        {
                            EntityMoniker = bu.ToEntityReference(),
                            State = state,
                            Status = status
                        };
    
                        OrganizationResponse oResponse = OrganizationService.Execute(request);

    I have set the default Status code and state values as described in this technet site

    I get no exception but still Business Unit is not disabled.

    Kindly suggest any workaround or solution.

    Thank you in advance.


    Rizwan Ahmed. Software Engineer - Microsoft Lync | Exchange | SharePoint | Blackberry Enterprise Server | .NET

    Saturday, March 28, 2015 12:18 PM

All replies

  • your code is correct and work (I tested it inside a CRM Online instance) 

    you can rewrite in this way:

    EntityReference buReference = new EntityReference("businessunit", BusinessUnitID);
    
    SetStateRequest request = new SetStateRequest()
    {
      EntityMoniker = buReference,
      State = new OptionSetValue(1),
      Status = new OptionSetValue(2)
    };
    
    OrganizationResponse response = OrganizationService.Execute(request);


    My blog: www.crmanswers.net - Rockstar 365 Profile


    Saturday, March 28, 2015 1:28 PM