与MenuItemDisplayStr()类似的函数作为非内在函数? (AX 2012)

时间:2016-04-21 18:19:52

标签: axapta dynamics-ax-2012 x++ dynamics-ax-2012-r3

我正在编写一个需要将字符串验证为现有menuItem的类。理想情况下,我需要类似于MenuItemDisplayStr()的东西,但我需要它在运行时使用该函数而不是编译时间。是否有类似的东西可以检查字符串,如果它是一个menuItem?

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您必须迭代AOT并将字符串与菜单项进行比较。

此代码改编自此处提供的示例: https://blogs.msdn.microsoft.com/dsiebold/2010/08/13/use-x-to-loop-through-the-aot/

#AOT

//These are the macros for the paths found in #AOT. 
//Don't use macros in practice. It's a bad habit.
//#define.MenuItemsDisplayPath('\\Menu Items\\Display')
//#define.MenuItemsOutputPath('\\Menu Items\\Output')
//#define.MenuItemsActionPath('\\Menu Items\\Action')

TreeNode menuItemParentNode;

//str menuItemName = "derp";//output: "derp is not a valid menu item"
str menuItemName = "ActivitiesMain";//output: "ActivitiesMain is a valid menu item"

//Only checking display here, you would need another level of 
//nodes to do output and actions.
menuItemParentNode = TreeNode::findNode(#MenuItemsDisplayPath);

if (menuItemParentNode.AOTfindChild(menuItemName))
    info(strFmt("%1 is a valid menu item", menuItemName));
else
    info(strFmt("%1 is not a valid menu item", menuItemName));