Search code examples
axaptadynamics-ax-2009user-permissions

Axapta User Permission


Im working on a report in AX2009 that will show what users have what permission, my question is,

how can i find through code (in x++) if user1 has got permission to post movement journals ?

thanks


Solution

  • Have a look at the SecurityKeySet class.
    For example, to check whether the user has access to the menu item InventJournalPost:

    SecurityKeySet userRights;
    MenuFunction   inventJournalPostFunction;
    AccessType     functionAccess;
    boolean        canPost;
    ;
    
    userRights = new SecurityKeySet();
    userRights.loadUserRights(curuserid()); // or any other user ID
    
    inventJournalPostFunction = new MenuFunction(
        menuitemactionstr(InventJournalPost),
        MenuItemType::Action);
    
    functionAccess = userRights.menuItemAccess(
        inventJournalPostFunction.name(),
        AccessRecordType::MenuItemAction);
    canPost = (functionAccess >= inventJournalPostFunction.neededAccessLevel());
    
    info(strfmt("User %1 post inventory journals", canPost ? "can" : "can not"));