SecRole.Create Method

The Create method creates a new role.

Syntax

[Visual Basic .NET]
Public Function Create(
  ByVal Caller As CUserAuth,
  ByVal RoleXML As String
) As String
[C#]
public string Create(
  CUserAuth  Caller,
  string  RoleXML
);
[C++]
public: String* Create(
  CUserAuth*  Caller,
  String*  RoleXML
);

Parameters

Caller

Specifies the identity of the caller. To perform this action, the caller must have the prvCreateRole privilege. See CUserAuth.

RoleXML

Specifies an XML string describing the role to be created. The role name and the business unit ID are required fields in the XML string. The XML schema is described by role.xsd.

Return Value

Returns a String type that specifies the returned ID of the newly created role.

Remarks

The name field in the parameter RoleXML must contain a unique role name.

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

[C#]
// 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";

// Create the URL to the SRF files for platform objects
string strDir = "https://" + strServer + "/" + strVirtualDirectory + "/";

// BizUser proxy object
Microsoft.Crm.Platform.Proxy.BizUser user = new Microsoft.Crm.Platform.Proxy.BizUser ();
user.Credentials = System.Net.CredentialCache.DefaultCredentials;
user.Url = strDir + "BizUser.srf";

// SecRole proxy object
Microsoft.Crm.Platform.Proxy.SecRole secRole = new Microsoft.Crm.Platform.Proxy.SecRole ();
secRole.Credentials = System.Net.CredentialCache.DefaultCredentials;
secRole.Url = strDir + "SecRole.srf";

// Declare the caller
Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = null;

string strSecRoleXML = "";
string strRoleId = "";
string strErrorMsg = "";

try
{
   // Get the UserAuth of the current logged-on user
   userAuth = user.WhoAmI();

   // Set up the XML string for the role in the business unit of the caller
   strSecRoleXML = "<role>" + 
      "<name>Custom Security Role Name</name>" + 
      "<businessunitid>" + userAuth.MerchantId + "</businessunitid>" +
      "</role>";

   // Create a custom role
   // The method returns the ID of the newly created role
   strRoleId = secRole.Create(userAuth, strSecRoleXML);
}
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 + "Source: " + err.Source );
}

Requirements

Namespace: Microsoft.Crm.Platform.Proxy

Assembly: Microsoft.Crm.Platform.Proxy.dll

See Also

© 2005 Microsoft Corporation. All rights reserved.