Share via


BizOrganization.CreateRootBusiness Method

The CreateRootBusiness method creates a root business unit and also the first user in the business unit. The user is assigned the System Administrator role. The caller must be a domain administrator to perform this action.

Syntax

[Visual Basic .NET]
Public Function CreateRootBusiness(
  ByVal OrganizationId As String,
  ByVal BusinessXML As String,
  ByVal UserXML As String
) As CBusinessResult
[C#]
public CBusinessResult CreateRootBusiness(
  string  OrganizationId,
  string  BusinessXML,
  string  UserXML
);
[C++]
public: CBusinessResult* CreateRootBusiness(
  String*  OrganizationId,
  String*  BusinessXML,
  String*  UserXML
);

Parameters

OrganizationId

Specifies the ID of the organization in which to create the root business unit. This ID is obtained when you create the Organizational Unit in Active Directory.

BusinessXml

Specifies an XML string containing the business information. The XML schema is described by businessunit.xsd.

UserXml

Specifies an XML string containing the user information. The XML schema is described by systemuser.xsd.

Return Value

Returns a String type that specifies a structure containing the newly created business unit ID and the user ID. See CBusinessResult.

Remarks

If there is an error, SOAP throws an exception and the error message is reported in System.Web.Services.Protocols.SoapException.Detail.OuterXml.

All IDs passed to the platform are GUIDs wrapped in braces. For example: {6522D89A-A752-4455-A2B0-51494C6957C3}

Example

Note The following example contains sample data for the administrator login name and password. This is for illustration only. User credentials should never be hard-coded. For more information, see Building Secure ASP.NET Applications, https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetch12.asp.

[C#]
// strServer should be set with the name of the platform Web server
string strServer = "myservername";

// virtualDirectory should be set with the name of the Microsoft CRM
// virtual directory on the platform Web server
string virtualDirectory = "mscrmservices";
string strDir = "https://" + strServer + "/" + virtualDirectory + "/";

// BizOrganization proxy object
Microsoft.CRM.Proxy.BizOrganization organization = new Microsoft.CRM.Proxy.BizOrganization ();
organization.Credentials = System.Net.CredentialCache.DefaultCredentials;
organization.Url = strDir + "BizOrganization.srf";

string strRootBizXML = "";
string strFirstUserXML = "";

// Get the GUID of an OU from Active Directory
// that is going to represent the OU for the Microsoft CRM organization object
// The name of the OU should be the same as the name of the Microsoft CRM organization
// The organization is created in Microsoft CRM
string strOrgId = "{3BECB6A6-0DD8-4061-98D9-0B9E897C5027}";

// See Note above regarding the use of hard-coded passwords
string strDomainAdminUserName = "Administrator";
string strDomainAdminUserPass = "Admin";
string strDomainName = "MyDomain";

Microsoft.CRM.Proxy.CBusinessResult BizResult = new Microsoft.CRM.Proxy.CBusinessResult ();

string strErrorMsg = "";

try
{
   // Set up the XML string for the business unit
   strRootBizXML = "<businessunit>" + 
                  "<name>Northwind Traders</name>" + 
               "</businessunit>";
            
   strFirstUserXML = "<systemuser>" + 
                     "<firstname>Robert</firstname>" +
                     "<lastname>Zare</lastname>" + 
                     "<domainname>DomainName</domainname>" +  
                  "</systemuser>";

   // Set the credentials of organization proxy with
   // credentials of a user that has domain administrator rights
   organization.Credentials = new System.Net.NetworkCredential(   strDomainAdminUserName, strDomainAdminUserPass, strDomainName);

   // Before calling this API make sure that
   // First user is created in Active Directory
   BizResult = organization.CreateRootBusiness(strOrgId, strRootBizXML, strFirstUserXML);
   // The user created here is going to be assigned the role of System Administrator
}
catch (System.Web.Services.Protocols.SoapException err)
{
   // Process the platform error here
   strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml + " Source: " + err.Source );
}
catch (Exception err)
{
   // Process other errors here
   strErrorMsg = ("ErrorMessage: " + err.Message );
}
finally
{
   // Set the credentials back to the default
   organization.Credentials = System.Net.CredentialCache.DefaultCredentials;
}

Requirements

Namespace: Microsoft.CRM.Proxy

Assembly: microsoft.crm.proxy.dll

See Also

© 2003 Microsoft Corporation. All rights reserved.