cancel
Showing results for 
Search instead for 
Did you mean: 

Context menu trouble

Former Member
0 Kudos

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());
  }
}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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>

Trinidad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

I have tried to reproduce your problem and I have succeeded.

I open my form once with a context menu.

I open my form a second time with a different UID but the same menu => Exception Menu already exists.

If I open my form using Xml the first time (I have saved my complete form in Xml and I load everything at once) then the context menu is Ok.

If I open my form a second time (with a different UID) then I have no error message but I have no context menu added to the form.

I think you should create a Customer Message to report this problem to the support. Maybe they can give you the right way to do it.

Please let as know if you find something interesting!

Regards

Trinidad.

Former Member
0 Kudos

Thanx, I'll try that, and if I get/find a solution (or not), I'll post it here...

Former Member
0 Kudos

Hello,

The following XML works for me

<?xml version="1.0" encoding="UTF-16"?>

<Application>

<forms>

<action type="add">

<form AutoManaged="0" BorderStyle="4" FormType="60006" ObjectType="-1" SupportedModes="15" appformnumber="60006" client_height="175" client_width="194" color="1" default_button="" height="200" left="300" mode="1" pane="0" title="Example1" top="150" type="4" uid="Example0" visible="1" width="200">

<datasources>

.....

</datasources>

<Menus/>

<items>

.....

</items>

<FormMenu>

<Menus>

<action type="add">

<Menu Checked="0" Enabled="1" FatherUID="5888" Image="" Position="0" String="Hello" Type="1" UniqueID="hello"/>

<Menu Checked="0" Enabled="1" FatherUID="5888" Image="" Position="0" String="World" Type="1" UniqueID="world"/>

</action>

</Menus>

</FormMenu>

<DataBrowser/>

</form>

</action>

</forms>

</Application>

Talk later,

Cormac

Former Member
0 Kudos

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

Answers (0)