Share via


SecRole.RetrieveRoleUsers Method

The RetrieveRoleUsers method retrieves the users that are assigned to the specified role.

Syntax

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

Parameters

Caller

Specifies the identity of the caller. The caller must have the prvReadRole privilege to perform this action. See CUserAuth.

RoleId

Specifies the ID of the role for which the users are being retrieved. This ID is specified by the platform and is obtained at creation time or by a bulk retrieve.

ColumnSetXML

Specifies an empty XML string used to define the columns that are to be returned. Passing "" or null returns all columns. You can find the valid column names in systemuser.xsd. See also ColumnSetXML Schema.

Return Value

Returns a String type that specifies the XML data describing the users that are returned. Only users to which the caller has READ access are returned. The XML schema is described by systemuser.xsd.

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

[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.Proxy.BizUser user = new Microsoft.CRM.Proxy.BizUser ();
user.Credentials = System.Net.CredentialCache.DefaultCredentials;
user.Url = strDir + "BizUser.srf";

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

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

string strErrorMsg;

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

   // Specify the columns that you want to retrieve
   string strColumnSetXml = "<columnset>";
   strColumnSetXml += "<column>fullname</column>";
   strColumnSetXml += "<column>systemuserid</column>";
   strColumnSetXml += "</columnset>";
   
   // Retrieve the role ID by name
   string strRoleId = secRole.RetrieveIdFromName(userAuth, userAuth.MerchantId, "System Administrator");
   string strUsersXml = "";
   if (strRoleId != null)
   {
      strUsersXml = secRole.RetrieveRoleUsers(userAuth, strRoleId, strColumnSetXml);
   }

}
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 );
}

// This returns something similar to the following:
// " <SystemUsers > <SystemUser > <systemuserid >{F99C752E-49DD-40CF-9770-1BB919D6B4EF} </systemuserid > <firstname >Erin </firstname > </SystemUser > </SystemUsers >"

Requirements

Namespace: Microsoft.CRM.Proxy

Assembly: microsoft.crm.proxy.dll

See Also

© 2003 Microsoft Corporation. All rights reserved.