In the second in this blog series I will show you how to make small changes via the UI API focusing on items:
1. Disable the Accounting tab in a Sales Order
Sometimes it might be necessary to prevent certain users from accessing information in a certain form. While this can't be controlled through the SAP Business One authorisations, it can be easily achieved via the UI API. The first option is to disable a tab - in this example we are disabling a tab/folder on the Business Partner form in Add, Find, OK and Update modes. It is important that you control this for the modes you wish to have it disabled. The following code should be copied into the ItemEvent:
If pVal.FormType = "139" Then
If pVal.FormMode = 0 Or pVal.FormMode = 1 Or pVal.FormMode = 2 Or pVal.FormMode = 3 Then
oform = SBO_Application.Forms.GetForm("139", 0)
oitem = oform.Items.Item("138")
oitem.Enabled = False
End If
End If
2. Make the Item Cost field on the Stock Data tab invisible
The ItemCost field is relevant only if the Valuation Method is set to Standard. In this example we do not want users to see this field so we will make both the textbox and it's associated label invisible. The following code should be copied into the ItemEvent:
If pVal.FormTypeEx = "150" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_GOT_FOCUS And pVal.FormMode = 3 Then
oform = SBO_Application.Forms.GetForm("150", 0)
oFolder = oform.Items.Item("26").Specific 'Stock Data tab
oFolder.Select() 'click on Stock Data tab
End If
If pVal.FormTypeEx = "150" And pVal.ItemUID = "26" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED And pVal.BeforeAction = False And pVal.ActionSuccess = True Then
oform = SBO_Application.Froms.GetForm("150", 0)
oform.Freeze(True) 'freeze to prevent flickering
oitem = oform.Items.Item("59") 'label
oitem.Visible = False
oitem = oform.Items.Item("64") 'textbox
oitem.Visible = False
oform.Freeze(False) 'unfreeze once done
End If
3. Add a new item on a System Form
When adding a new item on a system form its best to use an existing item on the form to position the new item. For example if we wish to add a new button on a Goods Receipt PO i will use the Cancel button as a marker to create the new one. The properties height, width and top will be the same as the exiting item but the left property needs to be increased otherwise the new button will be created over the Cancel button! The following code should be copied into the ItemEvent:
If pVal.FormTypeEx = "143" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD And pVal.BeforeAction = False Then
oform = SBO_Application.Forms.GetForm("143", 0)
oitem = oform.Items.Item("2") 'Cancel button
oNewItem = oform.Items.Add("NewButton", SAPbouiCOM.BoFormItemTypes.it_BUTTON)
oNewItem.Height = oitem.Height 'same height
oNewItem.Width = oitem.Width 'same width
oNewItem.Top = oitem.Top 'same top
oNewItem.Left = oitem.Left + 70 'add to the left so its positioned next to Cancel
oButton = oNewItem.Specific
oButton.Caption = "New Button"
End If
4. Automatically open a particular document
Sometimes you may need to open a certain form and do some automatic selections. For example after adding an Invoice automatically open an Incoming Payment for a certain BP and select the Invoice just added from the matrix.
Firstly we catch the event when the Invoice is added
Private Sub SBO_Application_FormDataEvent(ByRef BusinessObjectInfo As SAPbouiCOM.BusinessObjectInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.FormDataEvent
If BusinessObjectInfo.FormTypeEx = "133" And BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD And BusinessObjectInfo.BeforeAction = False And BusinessObjectInfo.ActionSuccess = True Then
SBO_Application.ActivateMenuItem("2817")
End If
End Sub
Then we add the following code to the ItemEvent to fill CardCode and select the newly added Invoice in the list.
If pVal.FormTypeEx = "170" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD Then
oform = SBO_Application.Forms.GetForm("170", 0)
oedit = oform.Items.Item("5").Specific 'CardCode
oedit.Value = "C20000"
oMatrix = oform.Items.Item("20").Specific 'matrix
vRowCount = oMatrix.RowCount 'count rows
For i = 1 To vRowCount
oedit = oMatrix.Columns.Item("1").Cells.Item(i).Specific
If oedit.Value = 14 Then
oCheckBox = oMatrix.Columns.Item("10000127").Cells.Item(i).Specific
oCheckBox.Checked = True
End If
Next i
End If
That's my last blog for 2009 so wishing you a lovely Christmas and every success in the New Year. I'll be back in 2010 with some more blogs that will hopefully be of use to you. So catch you then 🙂