B1 90 TB1300 03 Sol
B1 90 TB1300 03 Sol
B1 90 TB1300 03 Sol
1-1
1-1-2
1-1-3
Connect to the SAP Business One SboGuiApi and get a handle to the
running application.
SboGuiApi = New SAPbouiCOM.SboGuiApi
sConnectionString = Environment.GetCommandLineArgs.GetValue(1)
SboGuiApi.Connect(sConnectionString)
SBO_Application = SboGuiApi.GetApplication()
1-2
1-3
1-4
Define the AppEvent handler and implement the handling of these events
(which are mandatory to be handled).
Solutions can be found in the SDK Help Center documentation and SDK
samples (in the SDK Folder see Appendix SDK Installations for more
information),
COM UI / VB .NET / 01.HelloWorld
COM UI / VB .NET / 02.CatchingEvents
COM UI DI / VB .NET / Hello World
Solutions
Unit: User Interface API
Topic: Creating Forms
2-1
Create a new form within SAP Business One. The form should contain the
following items:
creationPackage.UniqueID = "TB1_DVDAvailability"
creationPackage.FormType = "TB1_DVDAvailability"
creationPackage.ObjectType = "TB1_DVDAvail"
oForm = SBO_Application.Forms.AddEx(creationPackage)
Button creation:
oItem = oForm.Items.Add("RentDVD",
SAPbouiCOM.BoFormItemTypes.it_BUTTON)
oItem.Left = 200
oItem.Width = 65
oItem.Top = 170
oItem.Height = 19
oButton = oItem.Specific
oButton.Caption = "Rent DVD"
oCFLCreationParams.ObjectType = "TB1_DVDAvail" Note this is the Code you gave in the wizard
when you registgered the UDO for TB1_DVD in the UDO exercises
oCFLCreationParams.UniqueID = "DVDCFL"
oCFL = oCFLs.Add(oCFLCreationParams)
EditText Creation
oItem = oForm.Items.Add("DVDNameT", SAPbouiCOM.BoFormItemTypes.it_EDIT)
oItem.Left = 90
oItem.Width = 163
oItem.Top = 25
oItem.Height = 14
oItem.LinkTo = "DVDNameL" link it to the associated Static
oEditText = oItem.Specific
oEditText.DataBind.SetBound(True, "", "DVDName")
oEditText.ChooseFromListUID = "DVDCFL"
2-2
Enhance your program so that the form will be saved as an XML file.
Firstly add a reference to Microsoft XML this references .NETs System.Xml
library
oXmlDoc = New Xml.XmlDocument
sXmlString = oForm.GetAsXML
oXmlDoc.LoadXml(sXmlString)
oXmlDoc.Save("File location \" & "DVDAvailability.xml")
2-3
Change your program. The form should now be loaded from the XML file you
have created in the last step. Display the form in the SAP Business One
window.
This code uses MSXML library so this is just for demonstration. Its
preferable to use LoadBatchActions for updates and Forms.AddEx to load
forms.
Private Sub LoadFromXML(ByVal Filename As String)
Dim oXMLDoc As MSXML2.DOMDocument
oXMLDoc = New MSXML2.DOMDocument
2-4
Use the tools from the B1TE toolset (essentially Form Checker) to check
whether you have designed your form(s) according to some important UI
guidelines
Similar solution can be found in the SDK UI samples (in the SDK Folder see
Appendix SDK Installations for more information),
COM UI/03.SimpleForm, 06.MatrixAndDataSources and 04.WorkingWithXML
413px
Width
557px
Controls common
Distance to left edge
5px
5px
5px
5px
Button
Height
19px
Width
65px
Spacing
5px
Label Field
Height
14px
Width
Depends on text
Horizontal spacing
>=12px (ungrouped)
Vertical spacing
1px (grouped)
>=3px (ungrouped)
Input Field
Height
14px
Width
Horizontal Spacing
>=12px (ungrouped)
Vertical spacing
1px (grouped)
>=3px (ungrouped)
Field Help
Vertical distance to input
field
1px
Matrix Objects
Width
Number of rows
Please note that more exhaustive information is available in the User Interface:
Standards and Guidelines in the SAP Business One Topic Search on SAP
Servicemarketplace at http://service.sap.com/smb/sbo/resources (October 2007).
Solutions
Unit: User Interface API
Topic: Additional Event Handling
3-1
3-2
Display the message "Caught Order FormLoad Event" when the FormLoad
event for the Order form arrives (use the Application.Message method).
SBO_Application.MessageBox("Caught Order FormLoad Event")
3-3
Catch the click event on the Rent DVD button you've added in the previous
exercise. Again display a message once the event is caught.
If FormUID = "TB1_DVDAvailability" And pVal.ItemUID = "RentDVD" And
pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then
SBO_Application.MessageBox("Caught click on Rent DVD button")
End If
3-4
oFilter = oFilters.Add(SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
oFilter.AddEx("139") 'Orders Form
oFilter.AddEx(TB1_DVDAvailability)
SBO_Application.SetFilter(oFilters)
Solutions
Unit: User Interface API
Topic: New Menu entries in SAP Business One window
4-1
Add a menu entry to the "Modules" menu called DVD Store. Those are the
menu entries which are also displayed in the Main Menu. Add a new sub-menu
to that menu entry called DVD Availability.
Dim oMenus As SAPbouiCOM.Menus
Dim oMenuItem As SAPbouiCOM.MenuItem
oMenus = SBO_Application.Menus
Dim oCreationPackage As SAPbouiCOM.MenuCreationParams
oCreationPackage =
SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_Me
nuCreationParams)
oMenuItem = SBO_Application.Menus.Item("43520") 'Modules
Dim sPath As String
sPath = Application.StartupPath
sPath = sPath.Remove(sPath.Length - 3, 3)
oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_POPUP
oCreationPackage.UniqueID = "TB1_DVDStore"
oCreationPackage.String = "DVD Store"
oCreationPackage.Enabled = True
oCreationPackage.Image = sPath & "dvd.bmp"
oMenus = oMenuItem.SubMenus
Try
oMenus.AddEx(oCreationPackage)
oMenuItem = SBO_Application.Menus.Item("TB1_DVDStore")
oMenus = oMenuItem.SubMenus
oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING
oCreationPackage.UniqueID = "TB1_Avail"
oCreationPackage.String = "DVD Availability"
oMenus.AddEx(oCreationPackage)
Catch er As Exception ' Menu already exists
SBO_Application.MessageBox("Menu Already Exists")
End Try
4-2
Handle the menu event: When you choose the menu entry, your form should be
displayed.
If pVal.MenuUID = "TB1_Avail" And pVal.BeforeAction = False Then
LoadFromXML("DVDAvailability.xml")
End If
Private Sub LoadFromXML(ByVal Filename As String)
Dim oXMLDoc As MSXML2.DOMDocument
Try
oXMLDoc = New MSXML2.DOMDocument
oXMLDoc.load("File location\" & Filename)
SBO_Application.LoadBatchActions(oXMLDoc.xml)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
4-3
Add another menu only visible when your form is open. This menu should
appear under the GoTo menu.
Dim oCreationPackage As SAPbouiCOM.MenuCreationParams
oCreationPackage =
SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_Me
nuCreationParams)
Dim oMenuForm As SAPbouiCOM.Form
oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING
oCreationPackage.UniqueID = "TB1_TestMenu"
oCreationPackage.String = "Test Menu"
oMenuForm.Menu.AddEx(oCreationPackage)
A similar solution can be found in the SDK UI samples (in the SDK Folder see
Appendix SDK Installations for more information),
COM UI/ 05.AddingMenuItems
Solutions
Unit: User Interface API
Topic: Data Binding
5-1
5-2
Bind the form's items with the corresponding data from the User Defined table
created in the DI exercises (TB1_DVD).
Firstly for each Edit Text field bind the field to its corresponding column in the
User defined table e.g.
oEditText.DataBind.SetBound(True, "@TB1_DVDAVAIL", "U_AISLE")
5-3
Get the data from the data sources and display them in the corresponding fields
on your form. Note you will first need to read the value selected by the user
from the Choose from List (Item Event) and then fill all other fields
accordingly.
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST Then
Dim oCFLEvent As SAPbouiCOM.ChooseFromListEvent
Dim oCFL As SAPbouiCOM.ChooseFromList
Dim CFLID As String
Dim oForm As SAPbouiCOM.Form
oCFLEvent = pVal
CFLID = oCFLEvent.ChooseFromListUID
oForm = SBO_Application.Forms.Item(FormUID)
oCFL = oForm.ChooseFromLists.Item(CFLID)
If oCFLEvent.BeforeAction = False Then
5-4