|
Blogs
In the first in this blog series I will show you how to make small changes via the UI API focusing on menu related activities:
Activate a Menu ItemIt's very easy to call/activate a menu from SAP Business One. Only one line of code is required: SBO_Application.ActivateMenuItem("2561") To find the string id required for each menu you can do the following:
Change a Menu captionTo change the menu caption we need to access the string value of the menu and give it a new name. In this example i have changed the 'Human Resources' menu to 'HR'. Again we need to access the Menu ID as we did in the previous example. Dim oMenus As SAPbouiCOM.Menus oMenus = SBO_Application.Menus oMenus.Item("43544").String = "HR"
Removing a MenuYou can remove a menu in Business One itself via the Form Settings for the Main Menu (using Visible property) but if you need to remove a menu via the UI it can be easily done. In our example we are removing the 'Document Printing' menu from the Sales module. Dim oMenus As SAPbouiCOM.Menus oMenus = SBO_Application.Menus oMenus.RemoveEx("2058")
Adding an option to the Right Click MenuThe right click menu allows you to increase the usability of your addon. In this example i added a new entry to the Right Click menu called 'Save as Draft'. I capture the click on the new menu event and activate the Save as Draft menu from the File menu in the toolbar. You can also do this for other menus also e.g. What's This? help menu for an explanation of each field.
Right Click EventPrivate Sub SBO_Application_RightClickEvent(ByRef eventInfo As SAPbouiCOM.ContextMenuInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.RightClickEvent If eventInfo.FormUID = "F_92" Then If (eventInfo.BeforeAction = True) Then Dim oMenuItem As SAPbouiCOM.MenuItem Dim oMenus As SAPbouiCOM.Menus Dim oCreationPackage As SAPbouiCOM.MenuCreationParams Try Dim oCreationPackage As SAPbouiCOM.MenuCreationParams oCreationPackage = SBO_Application.CreateObject (SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams) oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING oCreationPackage.UniqueID = "Draft" oCreationPackage.String = "Save as Draft" oCreationPackage.Enabled = True oMenuItem = SBO_Application.Menus.Item("1280") 'Data' oMenus = oMenuItem.SubMenus oMenus.AddEx(oCreationPackage) Catch ex As Exception MessageBox.Show(ex.Message) End Try End If End If End Sub
Menu EventPrivate Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.MenuEvent If pVal.MenuUID = "Draft" And pVal.BeforeAction = False Then SBO_Application.ActivateMenuItem("5907") End If End Sub
In two weeks time, we will continue with the UI API for Dummies blog series. So catch you then :-)
Lisa Mulchinock is a senior SDK support consultant for SAP Business One. Add to: del.icio.us | Digg | Reddit
| |||||||||||||||||||||