registerOverrideMethod of selectedMenuOption in System Form Extension

Hi everyone,

another similar question was posted here 2 years ago but didn’t received any replies.

I’m tring to add an item to the contextMenu of a FormControl,

i’ve succesfully overrided the method getContextMenuOptions and added the item.

Now i’ve tried to override the method selectMenuOption of the same FormControl but the new method never get executer nor it returns errors.

Here: https://community.dynamics.com/ax/f/microsoft-dynamics-ax-forum/219903/context-menu-using-registeroverridemethod you can find an example

The title says that you’re dealing with a form extension, but the thread you gave us as an example is about a completely different scenario (a form built from code; not an extension). Can you please clarify your actual situation?

It’ll help if you give us code that we can run. It’ll be clear what you’re doing and we won’t have to waste time writing the same code by ourselves, therefore you’ll have a much better chance that somebody will actually look at it.

Thank you for your reply and advice. Yeah, You are right and I was expecting a similar answer.

I’m extending the BatchJob Form, I want to add an item to the getContextMenuOption of every FormControl in the grid of the Form. Like I said this is working. The problem occurr overriding the selectedMenuOption of the FormControls that get not triggered selecting the item.

So if someone want to give a try, just create a new class named BatchJob_Extension and copy-paste the following code:

[ExtensionOf (formStr(BatchJob))]
final class BatchJob_Extension
{
    public const int listCreateRoot = 1;
    [FormEventHandler(formStr(BatchJob), FormEventType::Initialized)]
    public static void BatchJob_OnInitialized(xFormRun sender, FormEventArgs e)
    {
        object fsc;
        FormGridControl Grid;
        FormDesign des;
        FormTabControl tab;
        FormTabPageControl tabp;   
        int j;
        des = sender.design();
        tab = des.controlNum(3);
        tabp = tab.controlNum(1);
        Grid = tabp.controlNum(1);
        for(j=1 ; j <= Grid.controlCount() ; j++)
        {
            fsc = Grid.controlNum(j);
            fsc.registerOverrideMethod(methodStr(FormControl, selectedMenuOption), methodStr(BatchJob_Extension,"selectedMenuOption"), sender);
            fsc.registerOverrideMethod(methodStr(FormControl, getContextMenuOptions), methodStr(BatchJob_Extension,"getContextMenuOptions"), sender);
        }
    }
    public str getContextMenuOptions(FormControl _control)
    {
        int         item;
        ContextMenu menu = new ContextMenu();
        List menuOptions = new List(Types::Class);
        ContextMenuOption option = ContextMenuOption::Create("JustATry",listCreateRoot);
        menuOptions.addEnd(option);
        menu.ContextMenuOptions(menuOptions);
        
        return menu.Serialize();
    }
    public void selectedMenuOption(int selectedOption, FormControl _control)
    {
        info("I' working");
    }
}

This version uses Event but i tried either COC. Everyway going to the BatchJob Form and right-clicking somewhere in the grid the last item will be “JustATry” selecting it nothing will happend.

Thank to everyone will spend some time helping me.

Does it work if you use a form control extension and CoC?