User Roles retrieval:
To
retrieve
the roles of a particular
user based on username in
AX.
Tables:
The
user and their roles are relate with three different tables. All three tables are system tables and those tables are listed below,
1. SecurityUserRole
2. SecurityRole
3. UserInfo
Relation:
The
relations between those tables are,
1. Userinfo.Networkalias == username
2. SecurityUserRole.user
== userinfo.id
3. SecurityRole.recid ==
SecurityUserRole.securityrole
The
below job is used to List the roles of a particular user by Passing
the user name like a parameter.
static void retriveUserRoles(Args _args)
{
//Tables
SecurityUserRole _secUserRole;
SecurityRole _secRole;
UserInfo _userInfo;
//Parameter
NetworkAlias _userName = "Admin";
//List to store the roles
List userroles = new List(Types::String);
select _userInfo where _userInfo.networkAlias==_userName;
while select _secUserRole where _secUserRole.User==_userInfo.id
{
while select _secRole where _secRole.RecId == _secUserRole.SecurityRole
{
userroles.addEnd(_secRole.Name); //we can also add more role details in List
}
}
setPrefix("The roles assigned for user : " + _userName);
info(userroles.toString());
}
Output :
Thanks for read this blog.
No comments:
Post a Comment