Skip to Content
author's profile photo Former Member
Former Member

Context menu trouble

Hi there...

I've added a context menu item (thisForm.Menus.AddEx()) to the Item Master data form. The only problem is, this form can be opened more then once, and the context menu isn't visible in all instances, just the one I've it added to. That makes sense... 😊

But if I try to add the context menu item to the second instance, it trows a exception: "a menuitem with the same Unique ID already exists". The stupid thing: I check before I add if the menu item exists, and it says no, but if I try to add it: error... :S

I already checked if it existed in Application.Menus, but it does not exist there, it does not exist in ActiveForm.Menus, but if I try to add it it goes wrong...

Anybody any suggestions...?

<b>Code (C#)</b>

/// <summary>
/// This function adds a menuoption to the contextmenu of a specified form
/// </summary>
/// <param name="AFrm">The form</param>
/// <param name="AUid">The unique id of the menuitem</param>
/// <param name="ACaption">The caption of the menuitem</param>
/// <param name="APosition">The position, use -1 for none</param>
protected void AddContextMenuItem(SAPbouiCOM.Form AFrm, string AUid, string ACaption, int APosition)
    // Does this menu already exist?
      // Create a menuparameter object
      SAPbouiCOM.MenuCreationParams MCP = (SAPbouiCOM.MenuCreationParams)SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams);

      // Set the required parameters
      MCP.Type = SAPbouiCOM.BoMenuType.mt_STRING;
      MCP.UniqueID = AUid;
      MCP.String = ACaption;

      // Set the position?
      if(APosition >= 0)
        MCP.Position = APosition;

      // Add the menu
  catch(Exception e)
    // Exception handling

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 27, 2005 at 11:18 AM

    Hmz... Found something in the UI API:

    <i>We recommend using XML to add a form menu. This will allow your add-on to open multiple forms of the same type(with form menu) in parallel without getting exceptions on identical menu unique IDs. For more information, see the <FormMenu> element in Adding Forms with XML.</i>

    Okey, so I try to load the code below into SBO, but I get the error <i>"System.Runtime.InteropServices.COMException (0xFFFFE4A8): Form - Invalid"</i>. Anybody any suggestions...?


    <?xml version="1.0" encoding="UTF-16"?>
          <action type="update">
             <form FormType="150" appformnumber="150">
                <FormMenu type="add">
                   <menu UniqueId="LOCTRANS" Enabled="0" Position="8" String="V&amp;oorraadboekingslijst op locatie" Type="1"/>

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Cormac,

      I do it the same way for the sales invoices. But when I change the record (ex. goto the last), the context menu is disappeared.

      Do I have to add it each time I goto another record??

      I am using SBO2004A on PL18



Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.