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 Item
It'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:
- From the SAP Business One toolbar ensure View -> System Information is activated. When you hover over each menu in the toolbar you will find the associated menu id
- In the SDK Help File click on UI API -> Creating Menus -> List of Menu Item IDs for a full list of all menus
Change a Menu caption
To 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 Menu
You 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 Menu
The 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 Event
Private 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 Event
Private 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 🙂