Adding item to handheld menu list


(Michael Mahrle) #1

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?


(Chris Conn) #2

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


(Michael Mahrle) #3

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?


(Chris Conn) #4

What version of E10 are you using?


(Chris Conn) #5

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


(PatL) #6

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


(Michael Mahrle) #7

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.


(Michael Mahrle) #8

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


(Chris Conn) #9

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.


(Michael Mahrle) #10

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.


(Michael Mahrle) #11

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.


(Michael Mahrle) #12

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.