on 09-14-2016 3:10 PM
I am new to SAP Addon development and I am trying to build a few forms in C#, but I have a little problem with how I should load a Form and register menus.
Should an addon leave the buttons, menus it registered after shutting down the addon's executable? I develop in Visual Studio and when I start my addon, it first registers the menu elements, then the event handlers (these event handlers look for my menus to be pressed, then start a new form). If I shutdown the exe, the menus are still there and I think the forms too, even tough they are closed in SAP (If I restart the addon the menus are working again, but changes most of the time don't show without an SAP relog/restart). If I restart the SAP a menus disappear of course.
1. I create an SAPboui.Application, passed down it as parameter for the following methods
2. Register App Events
3. Register Menu Elements
( oCreationPackage = ((MenuCreationParams (SBOApp.CreateObject(BoCreatableObjectType.cot_MenuCreationParams))); .. )
4. Register Menu Event Handler
5. The menu event handler looks like this:
public void Listener(ref MenuEvent pVal, out bool BubbleEvent)
{
BubbleEvent = true;
if ((pVal.MenuUID == MenuRegister.MENU_ID_MODULE1) & (pVal.BeforeAction == false))
{
Module1 m = new Module1(SBOApp);
m.Display();
}
}
After the menu click, I create a module class, which then loads the Form from XML, registers its own event handlers and display the form.
Hi Szabolcs,
SAP does not remove anything when the add-on stops. There is an application object event you can capture to handle "clean up" tasks.
oApplication.AppEvent is the event and you should check the event type to be
BoAppEventTypes.aet_ServerTerminition
BoAppEventTypes.aet_ShutDown
ServerTerminition is for when the user asks the addon to be stopped.
Shutdown is for when the user closes B1 entirely.
Note that when using Visual Studio debug mode then none of those events occur when you just stop running the addon.
So, it's best practice to always check if the menu you're trying to add already exists, and only add it if it does not.
Pedro Magueija
If this answer was helpful or correct consider marking it as such.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And what is the best practice for Forms? I load them from XML every time a menu event starts (new Module()). Multiple modules from the same type can run at the same time, because of the different FormUID, but I also load them every time.
Edit.: Sorry for the long response, I am being moderated, because I am new 😧
Hi Szabolcs,
For forms that is ok. Every time there is a click on a given menu that should point to a form, you can load your form's xml, and by having a unique id for each one, you can have multiple forms of the same type opened just as you described.
Pedro Magueija
If this answer was helpful or correct consider marking it as such.
User | Count |
---|---|
89 | |
7 | |
6 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.