SecRole.AssignUsersToRoles Method
The AssignUsersToRoles method adds an array of existing users to an array of existing roles.
Syntax
[Visual Basic .NET]
Public Sub AssignUsersToRoles(
ByVal Caller As CUserAuth,
ByVal UserIds As String(),
ByVal RoleIds As String()
)
[C#]
public void AssignUsersToRoles(
CUserAuth Caller,
string[] UserIds,
string[] RoleIds
);
[C++]
public: void AssignUsersToRoles(
CUserAuth* Caller,
String* UserIds __gc[],
String* RoleIds __gc[]
);
Parameters
Caller
Specifies the identity of the caller. To perform this action, the caller must have the prvAssignRole privilege and access rights on the object to be modified. See CUserAuth.
UserIds
Specifies an array of user IDs to assign to the specified roles. This is an array of strings, each of which contains one user ID.
RoleIds
Specifies an array of IDs for the roles to which the user is being assigned. This is an array of strings, each of which contains one role ID.
Return Value
No return value.
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();
// Retrieve the role ID by name
string strRoleId = secRole.RetrieveIdFromName(userAuth, userAuth.MerchantId, "Sales Manager");
if (strRoleId != null)
{
string[] users = new string[1];
users[0] = userAuth.UserId;
string[] roles = new string[1];
roles[0] = strRoleId;
// Assign each of the roles to each of the users
secRole.AssignUsersToRoles(userAuth, users, roles);
}
}
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