cancel
Showing results for 
Search instead for 
Did you mean: 

AddOn Menus and changing the company

Former Member
0 Kudos

Hello forum,

I've written a little class (.NET) for adding and removing the menus of an AddOn (SBO 2004A).

Now I want to handle the behaviour of the AddOn Menus when changing the company (I test with 'Choose Company->Other' and logging in with the same(!) User and Company which raises the aet_CompanyChanged-Event so I think this is OK for testing).

It seems to me that there are some differences between 'Modules' and other SBO-Mainmenus:

- Under 'Modules' SBO removes AddOn Menus automatically when changing the company

- Under 'other SBO-Mainmenus' SBO does NOT remove the visibility(!) of AddOn Menus automatically when changing the company but the corrosponding AddOn-MenuUIDs are lost(?).

Because of the lost Menu-UID I don't know how to check if the AddOn Menus exists and remove them after Company Change.

Out of Modules my menu-class always don't find the Menu-UIDs of still visible Menus and add them again and again on every companyChange.

I wish there would be also a 'before_Action' for ApplicationEvents to remove the AddOn Menus.

How do you handle this problem?

Thanks in Advance

Roland

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Roland,

You are quite right about the different behaviors -- Menu added under Modules will remove automatically after company changes, but not for other menus.

In this case, if you want to avoid the annoying message "Menu is already exist!", you need to remove the menu in the event aet_CompanyChanged-Event. Here is a sample.

Dim oCreationPackage As SAPbouiCOM.MenuCreationParams

Dim oMenuItem As SAPbouiCOM.MenuItem
Dim oMenus As SAPbouiCOM.Menus

Set oCreationPackage = SBO_Application.CreateObject(cot_MenuCreationParams)


Set oMenuItem = SBO_Application.Menus.Item("4864") 'Tool UID
 '// Add String Menu Item
 oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING
 oCreationPackage.UniqueID = "MySubMenu"
 oCreationPackage.Position = "14"
 oCreationPackage.String = "Sub Menu"
 oMenuItem.SubMenus.AddEx oCreationPackage

 MsgBox "Menu is added! Begin to remove Menu!"

Set oMenus = SBO_Application.Menus
oMenus.RemoveEx "MySubMenu"

Best Regards,

Nick He

Message was edited by: Nick He

Former Member
0 Kudos

Hi there...

You can check if a menu already exists...

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


// Check if the menu exists
if( !MyApplication.Menus.exists("MyUID") )
{
  // Menu does not exist!
  // Your procedure to add a new menu :)
}

Former Member
0 Kudos

Thank you all for your answers.

(my news at the end of this message)

@J. Moolenaar:

But it seems VERY complicated (I think):

I had to catch the OK-Button-Event on the ChooseCompany Form and check if the User-Input in that Form really results in a CompanyChange.

@ Nick He & R. Schwachofer:

My menu-class-method takes care of existing (or not) menus:

I've made a collection-obj. of all my Menus and Submenus (a list of 40 menu-items - it's not a small project...)

When adding menus I step forward the collection and backward when removing menus (to asure not to remove a popup-menu which is not empty - a recursive-Function for removing should also be possible, but that's not the problem here I think).

The menu-class-method always checks while adding and removing if the MenuItem exists where I want to insert the new MenuItem AND it checks if the new MenuItem itself exists.

Under Modules it works perfect:

When the menu still exists it will be removed and when it's already destroyed by SBO it will be ignored and can be added again.

And now the NEWS(?):

Removing of AddOn-Menus out of Modules (Under 'Tools' in my case) after CompanyChange fails because the MENU-UIDs CHANGED BY SAP:

I stepped through the Tools-Menu before and after CompanyChange for test.

Before CompanyChange my MenuItem was called correct (Namespace is x-ed ;-):

UID: xxx_1 (short for test)

String: Menutest

After CompanyChange it's called:

UID: 52431 (it changes when restarting SBO and test again)

String: Menutest (still the same)

The solution (workaround) seems to be removing menus out of modules by their String-Property.

Former Member
0 Kudos

Hi Roland,

Now I see what's your problem.

In this case, I think you should get the menu by the position and string, then delete it.

BTW, is it possible to catch OK button click event on Choose Company form, then check some value, such as company DB name, user name to see if it's going to change company. If it does, remove your menus.

Best Regards,

Nick He

jaccomoolenaar
Participant
0 Kudos

Maybe you can catch the before menu event "Choose company" and remove your menu's. I haven't tried it, but I think it should work.

Regards