Create a Team

CRM 1.0

This sample creates a team with one member.

Class Reference

Schema Reference

  • team.xsd

Example

[C#]

// The precondition for this code to work is that there needs to be
// an organization, a business unit within the organization, and a user
// within the business unit whose 'domainname' corresponds to the 
// Active Directory name of the currently logged on user

public void CreateTeam()
{
   // strServer should be set with the name of the platform Web server
   String strServer = "MyServerName";

   // strVirtualDirectory should be set with the name of the Microsoft CRM
   // virtual directory on the platform Web server
   String strVirtualDirectory = "mscrmservices";
   String strDir = String.Concat("http://", strServer, "/",
                                 strVirtualDirectory, "/");

   // BizUser proxy object
   Microsoft.Crm.Platform.Proxy.BizUser bizUser 
               = new Microsoft.Crm.Platform.Proxy.BizUser ();
   bizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
   bizUser.Url = String.Concat(strDir, "BizUser.srf");

   // BizTeam proxy object
   Microsoft.Crm.Platform.Proxy.BizTeam team 
               = new Microsoft.Crm.Platform.Proxy.BizTeam ();
   team.Credentials = System.Net.CredentialCache.DefaultCredentials;
   team.Url = String.Concat(strDir, "BizTeam.srf");

   String strErrorMsg;
   try
   {
      Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = bizUser.WhoAmI();

      // Microsoft CRM business hierarchy directly maps to the Organizational
      // hierarchy in Active Directory. One constraint is that no two
      // child business units under the same location can have the same name.

      // In this context, a team also corresponds to an Active Directory
      // organization unit under the business unit in which it is created
      // and cannot have the same name as other items under the same place
      // (other teams, other child business units)

      StringBuilder teamXml = new StringBuilder("<team>");
      teamXml.Append("<name>MyTeam</name>");
      teamXml.Append("<businessunitid>");
      teamXml.Append(userAuth.MerchantId.ToString());
      teamXml.Append("</businessunitid></team>"); 

      String [] members = new String[1];
      members[0] = userAuth.UserId;

      // Create the team      
      String strTeamId = team.Create(userAuth, teamXml.ToString(),
                                     members);
   }
   catch (System.Web.Services.Protocols.SoapException err)
   {
      // Process the platform error here
      strErrorMsg = String.Concat("ErrorMessage: ", err.Message, " ",
                      err.Detail.OuterXml, " Source: ", err.Source);
   }
}


© 2005 Microsoft Corporation. All rights reserved.


Show: