As you may know there is an option to customize the navigation pane (which shows or hides modules), screenshots below.
From here you can hide/display multiple modules, now we can achive the same functionality from code for a specific role.
For this create a new class and within this new class 'HideAXModules' create a static method 'HideModulesForRole' and add following code within the static method,
public static void HideModulesForRole()
{
container cont_navButtons;
container cont_UserRoles;
TreeNode menunode;
TreeNode mainmenunode;
TreeNodeIterator menuitemiter;
str aotName;
int i = 1;
int j = 1;
int loc;
boolean isAdmin = false;
SecurityRole securityRole;
SecurityUserRole securityUserRole;
#AOT
#define.Zero('0')
#define.MainMenuLocation('\\Menus\\MainMenu')
//Fetch all roles for currently logged in User and insert in variable cont_UserRoles.
while select securityUserRole
join securityRole
where securityUserRole.User == curUserId()
&& securityRole.RecId == securityUserRole.SecurityRole
{
cont_UserRoles += securityRole.AotName;
if (securityRole.AotName == '-SysAdmin-')
{
isAdmin = true;
}
}
if (!isAdmin && conFind(cont_UserRoles, 'YourRoleName'))
{
mainmenunode = TreeNode::findNode(#MainMenuLocation);
menuitemiter = mainmenunode.AOTiterator();
menunode = menuitemiter.next();
while(menunode != null)
{
aotName = menunode.AOTname();
if(aotName == 'Home' || aotName == 'YourMenuName')
{
// Prefix 1 to show module
cont_navButtons = conIns(cont_navButtons, j, '1' + aotName);
}
else
{
// Prefix 0 to hide module
cont_navButtons = conIns(cont_navButtons, j, '0' + aotName);
}
j++;
menunode = menuitemiter.next();
}
// Hide Modules with 0 as prefix
infolog.navPane().setCurrMenuButtons(cont_navButtons);
}
}
Cheers!
From here you can hide/display multiple modules, now we can achive the same functionality from code for a specific role.
For this create a new class and within this new class 'HideAXModules' create a static method 'HideModulesForRole' and add following code within the static method,
public static void HideModulesForRole()
{
container cont_navButtons;
container cont_UserRoles;
TreeNode menunode;
TreeNode mainmenunode;
TreeNodeIterator menuitemiter;
str aotName;
int i = 1;
int j = 1;
int loc;
boolean isAdmin = false;
SecurityRole securityRole;
SecurityUserRole securityUserRole;
#AOT
#define.Zero('0')
#define.MainMenuLocation('\\Menus\\MainMenu')
//Fetch all roles for currently logged in User and insert in variable cont_UserRoles.
while select securityUserRole
join securityRole
where securityUserRole.User == curUserId()
&& securityRole.RecId == securityUserRole.SecurityRole
{
cont_UserRoles += securityRole.AotName;
if (securityRole.AotName == '-SysAdmin-')
{
isAdmin = true;
}
}
if (!isAdmin && conFind(cont_UserRoles, 'YourRoleName'))
{
mainmenunode = TreeNode::findNode(#MainMenuLocation);
menuitemiter = mainmenunode.AOTiterator();
menunode = menuitemiter.next();
while(menunode != null)
{
aotName = menunode.AOTname();
if(aotName == 'Home' || aotName == 'YourMenuName')
{
// Prefix 1 to show module
cont_navButtons = conIns(cont_navButtons, j, '1' + aotName);
}
else
{
// Prefix 0 to hide module
cont_navButtons = conIns(cont_navButtons, j, '0' + aotName);
}
j++;
menunode = menuitemiter.next();
}
// Hide Modules with 0 as prefix
infolog.navPane().setCurrMenuButtons(cont_navButtons);
}
}
Cheers!