UI API For Dummies – Part 3 DataSources
Happy New Year everyone!
In the third blog in this blog series I will show you how to use DataSources in your UI AddOn. DataSources allow you to work with data in UI forms and populate your forms with data. All items in your add-on forms (except it_STATIC and it_BUTTON items) must be bound to data sources in order to hold and manage data. As you know the UI API supports two types of data sources:
- Database Data Source – allows you to manage data from a table in the SAP Business One database.
- User Data Source – allows you to manage data defined internally for your add-on.
How to use DataSources
The steps to be followed for Data Binding are:
- Add the Data Source
- Set the Data Binding to specific item(s)
- Get Data from the DataSource
1. Add the Data Source
Here the table associated with the DBDataSource is the Invoices table OINV. You can control the records returned to the data source by creating a Conditions object and passing it with the Query method. For example returning only Invoices where the DocDueDate falls between June 1st and Dec 31st.
The difference between DBDataSource and UserDataSource is that the UserDataSource holds one value at any time assigned to it by a user.
oForm.DataSources.UserDataSources.Add(“UserData”, SAPbouiCOM.BoDataType.dt_LONG_TEXT, 30)
2. Bind the Data
After adding the data source, you bind it to your item using the method SetBound.
oMatrix = oForm.Item.Item(“Matrix”).Specific
oColumns = oMatrix.Columns
oColumn = oCoumns.Item(“CardCode”)
Bind the data to the respective column
oColumn.DataBind.SetBound(True, “OINV”, “CardCode”)
Bind a UserDataSource to a column – table name will be empty
oEdit = oForm.Items.Item(“Remarks”)
oEdit.DataBind.SetBound(True, “”, “UserData”)
3. Get data from DataSources
Query the datasources already defined above. You cannot run this method on a DBDataSource bounded to a system forms. The system will throw an exception.
You still need to control adding data to the database by using the object/service of the DI API.
Returns or sets a value in the data source in database format only. You can use Get
oUserDataSource.Value = “Tested by Lisa”
While having matrix columns bound to a UserDataSource, it is more efficient to update the matrix cells using GetLineData and SetLineData methods (of the matrix object).
Use SetLineData for taking the data from the matrix into the DataSource.
Use GetLineData for loading data from your DataSource to the matrix.
It’s important to note that updating the DataSource value is valid only currently for UserDataSources.
Set oMatrix = oForm.Items.Item(“Matrix”).Specific
Set oColumn = oMatrix.Columns.Item(“MyCol”)
Set UDS = oForm.DataSources.UserDataSources.Item(“UserData”)
UDS.Value = “My New Value”
In two weeks time, we will continue with the UI API for Dummies blog series. So catch you then 🙂