Extend Matrix on offer form by a custom menu point
Mark
Hello Forum,
I'm working on an Addin for article analysis. It should extend the article matrix on the offer form in B1. If the user wants to get one of the articles in the offer be analysed, he should make a right click on a row and chose "Analyse article". Additional there should be some other menu points be added for other tasks. The basic problem is that all menu points are visible all the time: The user makes a right click on one of the textboxes or even in complete different forms.
My first try was to register the GetFocus/Lostfocus event for the offer form matrix:
Matrix m = Matrix.GetFromUID(OfferForm, "38");
m.AddHandler_GotFocus(ModeComponent.FormModes.ADD, GF_Before);
m.AddHandler_LostFocus(ModeComponent.FormModes.ADD, LF_Before);
m.AddHandler_RightClick(null, RC_After);
But they are never caught!? For testing I have registered also the Right Click event, but this event is also very unreliable. It is only caught if I make a right click on the matrix and then click on another control. At the moment when the LostFocus should happen, the right click event is caught.
Another solution could be to register for the B1 Application.ItemEvent. There I can see the LostFocus/GotFocus events for the matrix. Depending on the events I can add and remove the menu items. On my testing machine it works like a charm! But if I install it in the productive system I got a lot of problems. I will explain the problems later. This problems happen even with an nearly empty App_ItemEvent handler like below:
SwissAddonFramework.B1Connector.GetB1Connector().Application.ItemEvent += this.App_ItemEvent;
...
protected virtual void App_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent) {
//SwissAddonFramework.Messaging.StatusBar.WriteError("App_ItemEvent()");
BubbleEvent = true;
}
I unregister my "App_ItemEvent()" function if I catch the Form_Unload event. So I'm thinking its not a problem of freeing resources.
Now the funny problems.
1. In the productive system are rules that opens other receipts. For example if this line is executed:
SwissAddonFramework.UI.Components.Form.OpenFormByKey(FormID, "1821"); // FormID=17, which means Customer Order form
At normal this line of code opens a Customer Order form with the DocEntry "1821". But if I activate my addin, additionally a second offer form with DocEntry "17" is opened (its a form with a offer). You could guess that the FormID is also used as a DocEntry. Lets prove it!
SwissAddonFramework.UI.Components.Form.OpenFormByKey(FormID, "1521"); // FormID=23. which means offer form.
If my addin is active not only the receipt 1521 is opened, the receipt with the DocEntry 23 is opened too!
2. At normal B1 uses Crystal Reports for printing receipt. But this function is turned off in our productive system, because we are using the Coresuite reports. If my addin is active, the Coresuite printing dialog AND the crystal reports printing dialog is opened.
3. If my addin is active and if I close B1, Coresuite crashes in the end.
Currently I'm using a lot of workarounds: To avoid problem 1) I'm registering the App_ItemEvent() events not in the form_load event, I'm using a timer that delays the App_ItemEvent registering 1 second after the Form_Resize Event has happened. To avoid problem 2) I'm catching the printing menu has clicked event. I they happen: I unregister my App_ItemEvent() event and If the form gets the focus again, I register the events again.
But this are only workarounds. Maybe in some days I will get further problems I have to build workarounds for.
So how can I create menu items that are only visible above the matrix or another specific control?
Thanks
Mark
Please sign in to leave a comment.
Comments
0 comments