TechNinjutsu‎ > ‎

Find security duties related to menu item in Dynamics AX 7(365 for Operations)

posted Mar 1, 2017, 10:16 PM by d graham   [ updated Mar 3, 2017, 12:28 AM ]
using Microsoft.Dynamics.AX.Security.Management;
using Microsoft.Dynamics.AX.Metadata.Providers;

class jTest
{
    public static void main(Args _args)
    {
        jTest j = new jTest();
        
        SecurityRepository sr = new SecurityRepository(null, null);
        Querying.RelatedSecurityRolesFinder rsrf = new Microsoft.Dynamics.AX.Security.Management.Querying.RelatedSecurityRolesFinder(sr);

        j.getDisplayRelatedDuties("PurchTable", rsrf);
        j.getOutputRelatedDuties("PurchInvoice", rsrf);
        j.getActionRelatedDuties("PurchTableApprovalApprove", rsrf);
       
    }

    private void getActionRelatedDuties(str _actionMenuItem, Querying.RelatedSecurityRolesFinder _rsrf)
    {
        SecurityObjectsBag sob = _rsrf.FindRelatedSecurityObjectsForMenuItemAction(_actionMenuItem);
        this.displaySobDuties(sob);
    }

    private void getDisplayRelatedDuties(str _actionMenuItem, Querying.RelatedSecurityRolesFinder _rsrf)
    {
        SecurityObjectsBag sob = _rsrf.FindRelatedSecurityObjectsForMenuItemDisplay(_actionMenuItem);
        this.displaySobDuties(sob);
    }

    private void getOutputRelatedDuties(str _actionMenuItem, Querying.RelatedSecurityRolesFinder _rsrf)
    {
        SecurityObjectsBag sob = _rsrf.FindRelatedSecurityObjectsForMenuItemOutput(_actionMenuItem);
        this.displaySobDuties(sob);
    }

    private void displaySobDuties(SecurityObjectsBag _sob)
    {
        info(_sob.ToString());
        using(var dutiesEnumerator = _sob.Duties.getEnumerator())
        {
            while(dutiesEnumerator.MoveNext())
            {
                Interfaces.ISecurityObject d = dutiesEnumerator.Current;
                info(strFmt("%1, %2", d.Name, d.Identifier));
            }
        }
    }

}
Comments