Thursday, August 11, 2016

Hiding module based on User Roles ax 2012

// Hiding module based on User ROles ax 2012

//Info-->StartUpPost--> (Call Below class Method)

//Change Company
 Method --> SwitchCompanyForm--> SysDataAreaSelect//Disabling User Access over Companies

//Disabling Access in Navigation Pane

Method --> Ok (Clicked)Form --> SysNavPaneOptionsDialog//User Level Restrict Navigation Pane button


New Class-->
class EPG_SpecificRoleModuleEnable
{
}
Method-->
public static void disablingNavigationOptionsCrossCompanies()
 {
     DataArea        dataArea;
     SysLastValue    sysLastValue, sysLastValueCheck;
     ;
     select sysLastValue
        where  sysLastValue.company == curext()
                && sysLastValue.userId == curUserId()
                 && sysLastValue.elementName == "Usersetup"
                   && sysLastValue.designName == "NavPaneOptionsButtons";
     if (sysLastValue)
     {
         while select id from dataArea
             where !dataArea.isVirtual
                    && dataArea.Id != curext()
         {
             select forUpdate sysLastValueCheck
                 where sysLastValueCheck.company == dataArea.Id
                        && sysLastValueCheck.userId == curUserId()
                         && sysLastValueCheck.elementName == "Usersetup"
                           && sysLastValueCheck.designName == "NavPaneOptionsButtons";
             ttsBegin;
             sysLastValueCheck.company = dataArea.Id;
             sysLastValueCheck.userId = curUserId();
             sysLastValueCheck.elementName = sysLastValue.elementName;
             sysLastValueCheck.recordType = sysLastValue.recordType;
             sysLastValueCheck.designName = sysLastValue.designName;
             sysLastValueCheck.isKernel = sysLastValue.isKernel;
             sysLastValueCheck.value = sysLastValue.value;
             sysLastValueCheck.write();
             ttsCommit;
         }
     }
 }

Method --> 2
public static void disableModulesbyUserRole()
 {
     container   navigationButtons;
     container   SpecUserRoles;
     container roleName = ["System administrator"];
     TreeNode            MenuNode;
     TreeNode            MainMenu;
     TreeNodeIterator    MenuItem;
     str aotName;
     int i = 1;
     int j = 1;
     int local;
     boolean isAdmin = false;
     SecurityRole        securityRole;
     SecurityUserRole    securityUserRole
    
     #define.MainMenuPath('\\Menus\\MainMenu')
     ;
     while select securityUserRole
         join securityRole
             where securityUserRole.User ==  curUserId()
                 && securityRole.RecId == securityUserRole.SecurityRole
     {
         SpecUserRoles += securityRole.AOTName;
         if (conFind(roleName,securityRole.Name))
         {
             isAdmin = true;
         }
     }
     if (!isAdmin && conFind(SpecUserRoles,'EPG_FinanciaRole'))
     {
         MainMenu       = TreeNode::findNode(#MainMenuPath);
         MenuItem       = MainMenu.AOTiterator();
         MenuNode       = MenuItem.next();
         while(MenuNode != null)
         {
             aotName = MenuNode.AOTname();
             if(aotName == 'Home' || aotName == 'Payroll')
             {                
                 navigationButtons = conIns(navigationButtons, j, '1' + aotName); //1 to Enable module
             }
             else
             {                
                 navigationButtons = conIns(navigationButtons, j, '0' + aotName); //0 to Disable module
             }
             j++;
             MenuNode = MenuItem.next();
         }
         infolog.navPane().setCurrMenuButtons(navigationButtons);
        
         EPG_SpecificRoleModuleEnable::disablingNavigationOptionsCrossCompanies();
     }
 }

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...