SecRole.RetrieveUserRoles Method
The RetrieveUserRoles method retrieves all roles for the specified user.
Syntax
[Visual Basic .NET]
Public Function RetrieveUserRoles(
ByVal Caller As CUserAuth,
ByVal UserId As String,
ByVal ColumnSetXML As String
) As String
[C#]
public string RetrieveUserRoles(
CUserAuth Caller,
string UserId,
string ColumnSetXML
);
[C++]
public: String* RetrieveUserRoles(
CUserAuth* Caller,
String* UserId,
String* ColumnSetXML
);
Parameters
Caller
Specifies the identity of the caller. To perform this action, the caller must have the prvReadRole privilege and access rights on the objects being retrieved. See CUserAuth.
UserId
Specifies the ID of the user for which the roles are to be retrieved. This ID is specified by the platform and is obtained at user creation time or by a bulk retrieve.
ColumnSetXML
Specifies an empty XML string used to define the columns that are to be returned. Passing an empty string or null returns all columns (Nothing or "" in VB .NET). You can find the valid column names in role.xsd. See also ColumnSetXML Schema.
Return Value
Returns a String type that specifies the XML data describing the roles that are returned. This XML string is in the format
<roles> + role1..N + </roles>
where the XML schema for each role is described by role.xsd.
Remarks
Unlike the Retrieve method, the XML string returned from this method may contain multiple objects. If no objects are returned the method simply returns an XML document for the object type with no data.
The XML string returned from this method does not contain elements for fields where the value is null or contains empty strings. This improves performance by not sending more XML data than is necessary from the server to the client.
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 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>name</column>";
strColumnSetXml += "<column>roleid</column>";
strColumnSetXml += "<column>organizationid</column>";
strColumnSetXml += "</columnset>";
string strRolesXml = "";
strRolesXml = secRole.RetrieveUserRoles(userAuth, userAuth.UserId, 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 method returns something similar to the following:
// " <roles> <role> <roleid>{C75FAB25-84A2-4C95-86D8-00161F7F087A} </roleid> <name>David Ortiz</name> </role> </roles>"
Requirements
Namespace: Microsoft.Crm.Platform.Proxy
Assembly: Microsoft.Crm.Platform.Proxy.dll
See Also