Temporarily toggle admin mode in Dynamics AX 2012

The information in this post is based on Dynamics AX 2012 R3. It may or may not be valid for other versions.

Sometimes – especially when testing security elements – it is convenient to be able to temporarily disable your own administrator privileges. Of course, you could just remove yourself from the Administrators group, but that holds a very real risk of you locking yourself out of the system and needing assistance to get back in.

If you just need to be without administrative privileges temporarily in a single session, you can execute the below job instead. It simply toggles back and forth between admin mode, so just run it again to regain your administrator awesomeness.

static void ToggleAdminMode(Args _args)
    info(strFmt('Admin mode: %1', SecurityUtil::sysAdminMode()));

Toggling administrative privileges this way also has the advantage that if you mess up and lose access to something you need, you can just restart the Dynamics AX client, at which point your privileges will be restored to normal.