web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to change the Label of a Menu from X++?

(0) ShareShare
ReportReport
Posted on by 792

Hi All,

I have a Menu in Dynamics AX 2012 and set up its Label 'ABCD' from Properties pane in AOT. I have also set up its reference inside MainMenu.

Now what I want, is to change this Label value programmatically (i.e. from X++ code) if a particular condition is true. That is I want to make the Label of that Menu change to 'XYZ' (if some p > q).

Is it possible programmatically? And if yes, plz suggest a way.

Thanks & Regards.

Sagnik.

*This post is locked for comments

I have the same question (0)
  • Bilal Issa Profile Picture
    4,370 on at

    Hi ,

    Yes, that is possible,  please check the link below, it is used for form, but you can do the same for menu item.

    blogs.msdn.com/.../use-x-to-loop-through-the-aot.aspx

    Regards,

    Bilal

  • Verified answer
    Iulian Cordobin Profile Picture
    8,201 on at

    You could use something like this:

    static void changeLabel(Args _args)

    {

       TreeNode node;

       node = TreeNode::findNode("\\Menu Items\\Display\\AccountingDistributions");

       if (node != null)

       {

           info(strFmt("Old value: %1", node.AOTgetProperty("Label")));

           node.AOTsetProperty("Label", "Your value");

           info(strFmt("New value: %1", node.AOTgetProperty("Label")));

       }

    }

  • Sagnik Majumder Profile Picture
    792 on at

    Hi Bilal, the link you have shared doesn't solve the purpose.

    I want to know is there any way to set the Label text for a particular Menu? Eg:-

    myMenu.setLabel("MyLabel");  --> any method like this?

    I have tried using DictMenu, but still can't set its Label. I am able to Get the Label value, but not Set it.

  • Iulian Cordobin Profile Picture
    8,201 on at

    You need a lower level of reflection than Dict*, the TreeNode should give you what you need. But I am not sure I understood, you need to change the label in the Menu or on the Menu Item?

  • Bilal Issa Profile Picture
    4,370 on at

    I agree with Iulian ,  node.AOTsetProperty("Label", "Your value"); should do it.

  • Zisis Profile Picture
    40 on at

    If we are talking about a menu (and not a button or something o a form) I dont think that this is possible. The menus lables etc are cached when the user opens the client.

  • Iulian Cordobin Profile Picture
    8,201 on at

    Hi Sagnik,

    Did the solution provided worked for you, or the request was misunderstood and you actually needed to change the label for a Menu, in which case, this is not possible - the TreeNode reflection doesn't work on menus because the property you would change is 'Name' not label (at least from my knowledge).

  • Sagnik Majumder Profile Picture
    792 on at

    Hi Iulian, thanks for your answer. First of all I would like to tell you that I wanted to change the label of a Menu (and not a menuitem).

    I worked on your TreeNode solution, and found that the Menu label is indeed changed from "OldValue" to "NewValue". But the problem is you have to restart the AX client once for this change to reflect. Though that is not a big blunder in my scenario, but the problem is, as I am using version control for my classes and forms, hence it requires to Check Out that particular Menu in AOT, and only then, it can apply the label change. This, for me, is a big catch.

    Can you suggest any way to overcome this?

  • Verified answer
    Sagnik Majumder Profile Picture
    792 on at

    Sorry, I took a deeper look at the TreeNode class and found the option.

    Its the treenode.AOTAllowEdit();

    This function worked like magic for me. It didnot require me to check out the AOT Menu, instead it silently removed the read-only property of that Menu element and set the Label property and saved it.

    Complete code snippet:-

    node = TreeNode::findNode('\\Menus\\MyMenu');

    if (node != null && 2 > 1)

    {

          node.AOTAllowEdit();

          node.AOTsetProperty('Label', 'New Label');

          node.AOTsave();

      }

    With this my query gets resolved. Thanks to all of u guys....

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans