SecRole.RetrieveRolePrivileges Method
The RetrieveRolePrivileges method retrieves the privileges that are assigned to the specified role.
Syntax
[Visual Basic .NET]
Public Function RetrieveRolePrivileges(
ByVal Caller As CUserAuth,
ByVal RoleId As String
) As CRolePrivilege()
[C#]
public CRolePrivilege[] RetrieveRolePrivileges(
CUserAuth Caller,
string RoleId
);
[C++]
public: CRolePrivilege* RetrieveRolePrivileges(
CUserAuth* Caller,
String* RoleId
) __gc[];
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 to be retrieved. See CUserAuth.
RoleId
Specifies the ID of the role for which the privileges are to be retrieved. This ID is specified by the platform and is obtained at creation time or by a bulk retrieve.
Return Value
Returns a CRolePrivilege[] type that specifies an array of structures containing the IDs and depths of the privileges held by the specified role. See CRolePrivilege.
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.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();
// Create an array of privileges to add to the desired role
Microsoft.Crm.Platform.Proxy.CRolePrivilege[] rolePrivileges = new Microsoft.Crm.Platform.Proxy.CRolePrivilege[20];
// Retrieve the role ID by name
string strRoleId = secRole.RetrieveIdFromName(userAuth, userAuth.MerchantId, "Salesperson");
if (strRoleId != null)
{
rolePrivileges = secRole.RetrieveRolePrivileges(userAuth, strRoleId);
}
}
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