9 Mart 2021 Salı

D365 F&O - Add right-click popup menu to form control

 In 2015 I shared a sample  about this issue which run both of AX 2009 and AX 2012. Seem Microsoft decided to change this too with 365, so that code doesn't run on 365 anymore. Microsoft shared a white page as before-after, I learned from that page. It was run with one method, since 365 two methods.

We declare these constants at class declaration. Of course these are not mandatory but good for writing human readable code:

public const int listCredit = 1;

public const int listJournal = 2;

We put this metod into control which we run popup. This method run popup menu. This sample has two popup bars:

        public str getContextMenuOptions()
        {
            str ret;
            ContextMenu menu = new ContextMenu();
            List menuOptions = new List(Types::Class);
            ContextMenuOption option;
            
            option = ContextMenuOption::Create("Credit number", listCredit);
            menuOptions.addEnd(option);

            option = ContextMenuOption::Create("Journal number", listJournal);
            menuOptions.addEnd(option);

            menu.ContextMenuOptions(menuOptions);
            return menu.Serialize();
        }

  This method triggers when select a bar at popup:

 public void selectedMenuOption(int selectedOption)
        {
            switch (selectedOption)
            {
                case -1:
                    break;
                case listCredit:

                    info("Bar 1 selected!..");
                    break;
                case listJournal:
                    info("Bar 2 selected!..");
                    break;
            }
        }

In my tests popup menu sometines doesn't showed up. I never see before at neither 2012 nor 2009. I couldn't find reason. When debugged see getContextMenuOptions doesn't triggered when bars doesn't showed up.

Hiç yorum yok:

Yorum Gönder