Skip to Content
author's profile photo
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)
{
  try
  {
    // Does this menu already exist?
    if(!AFrm.Menu.Exists(AUid))
    {
      // 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
      AFrm.Menu.AddEx(MCP);
    }
  }
  catch(Exception e)
  {
    // Exception handling
    Debug.WriteLine(e.ToString());
  }
}

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    author's profile photo
    Former Member
    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...?

    Thnx

    <?xml version="1.0" encoding="UTF-16"?>
    <Application>
       <forms>
          <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"/>
                </FormMenu>
             </form>
          </action>
       </forms>
    </Application>
    

    Add 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

      Greetz

      Eddy