Adding item to handheld menu list

After looking through here I found an example of adding menu list items originally posted by the inimitable Jose Gomez that I’ve tried to re-implement in C#. However, I get the “Object reference not set to an instance of an object” error on the invoke method. The declaration of the MethodInfo object executes without an exception. Here’s my code:

    MethodInfo mi = typeof(Erp.UI.Menu.Handheld.Transaction).GetMethod("addMenuItem",BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[]{typeof(int),typeof(int),typeof(String),typeof(String)},null);
	mi.Invoke(oTrans, new object[] {6,0,"Menu Text","MenuID"});

Although this code for GetMethod has apparently worked for other people based on several entries in here it returns null for me. I’ve placed it in the form_load function for HHMenu.

Can anyone point out my error?

I am unsure of the exact issue but i have some things to check.

I think the issue is that you havent actually set a MENU ID. Look in the menu maintenance, find the screen you want to open, copy the ID

MethodInfo mi = oTrans.GetType().GetMethod("addMenuItem",  BindingFlags.Instance | BindingFlags.NonPublic,null,CallingConventions.Any,  new Type[]{typeof(int), typeof(int), typeof(string),typeof(string), typeof(string)}, null);
mi.Invoke(oTrans, new object[]{6,1,"Title", "MenuID","M"});   //where MenuID is the MENU ID from Menu Maintenance for the desired screen

The menu structure is weird, you cant have any gaps in the numbers. It looks like 6,0 is menu item for KanBan Receipts. Try 6,1

1 Like

Thanks for the reply. You may well be right regarding the invoke statement but my problem is that I don’t have an mi object to invoke. The GetMethod statement is returning null. It doesn’t throw an exception when executed. It just doesn’t return a MethodInfo object.

Do you know where I can find the signature for the addMenuItem method?

What version of E10 are you using?

I notice you aren’t defining the CallingConventions parameter in your GetMethod()

With 10.2 the handheld menu is now in the database.
MESMenu i think is the table.

I’m using 10.2.200.1 in a multi-tenant hosted environment. Thanks for the interface definition. Where do I find that? I know I’ve seen it before but I don’t remember how I got there.

I was just copying what others had posted as working for them. I’ll try that as well.

10.2 and multi-tenant hosted. I am not familiar that particular flavor. Get you a decompiler like ILSpy or Reflector and open up that erp.menu.handheld.dll (assuming you have a physical client - like I said, I have no exposure to hosted) and you should find it.

Yes, you’re right. There’s no longer an addMenuItem method in Erp.UI.Menu.Handheld.Transaction. Looks like you have to add items to the table directly.

I was able to decompile the dll and found that there’s no longer an addMenuItem method there. That explains the null return from GetMethod. Looks like you have to add the items directly to a table.

1 Like

Chris, your email to me was a great help. I’ll admit I probably wouldn’t have thought of using class factory. Anyway, I had to add a couple of column values but it works perfectly.

I’m replying to you this way because replying to your email didn’t work and I don’t know a direct email for you.

1 Like