Tuesday, November 17, 2015

Hiding Dynamics AX modules for a specific role

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!

Monday, November 16, 2015

Calculating sales price

To calculate sales price of an item first you need to setup few things in Retail.

1) Ensure your login is linked to one of the retail channels.

2) 1.      If you want any price or discounts to appear on the sales line then affiliation and product setup needs to be performed
a.      Affiliation: Ensure the customer is linked to an affiliation

a.      Ensure that the item is linked to a proper product category.


Now use code sample mentioned in this blog to calculate sales price of an item.

Cheers!