Good afternoon,
I have an issue which I think is strange, but everything is strange as I am completely new to this.
I have written an add-on in vb.net that is fired when an AR Invoice is created with non stock items in the matrix.
I am pleased to report that everything works wonderfully.... once.
Therein lies my problem.
When the add button is clicked, my code fires before_action as expected. The Invoice is saved - all good - however if you then create another invoice the itemevent procedure in my code doesn't fire. It is like my add-on is disconnected once it has run once.
What am I missing? - it has to be something simple, but I have hunted for 2 hours now and am running out of ideas.
Code shown below.
Thanks in advance,
Kevin McGinn
CODE:
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
If (pVal.FormType = 133 And pVal.EventType < > SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD) Then
oFormARInvoice = SBO_Application.Forms.GetFormByTypeAndCount(133, pVal.FormTypeCount)
If (pVal.ItemUID = "1") And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED) And (pVal.Before_Action = True) Then
uibutton = oFormARInvoice.Items.Item("1").Specific
If uibutton.Caption = "Add" Then
'** Need to force the item cost for non stock items to be saved
'*************************************************************************************
Dim oIndex As Integer
Dim uItemCode As String
uiMatrix = oFormARInvoice.Items.Item("38").Specific
For oIndex = 1 To uiMatrix.RowCount
uiEditText = uiMatrix.Columns.Item("1").Cells.Item(oIndex).Specific
uItemCode = uiEditText.String
'Check for non stock items first
Dim oItemRecSet As SAPbobsCOM.Recordset
oItemRecSet = Nothing
oItemRecSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
oItemRecSet.DoQuery("SELECT InvntItem FROM OITM WHERE ItemCode = '" & uItemCode & "'")
Dim isNonStock As Boolean
isNonStock = False
Do While Not oItemRecSet.EoF And isNonStock = False
isNonStock = oItemRecSet.Fields.Item("InvntItem").Value = "N"
oItemRecSet.MoveNext()
Loop
'if we have a non stock item, then we need to force in the item cost
'in the gross profit screen
If isNonStock = True Then
'Got at least one, now we need to open the 241 (Gross Profit) form and force the
'avgprice field from the OITM table into the matrix
SBO_Application.ActivateMenuItem("5891")
oFormGrossProfit = SBO_Application.Forms.GetForm("241", 1)
uiMatrixGP = oFormGrossProfit.Items.Item("3").Specific
uiColumns = uiMatrixGP.Columns
Dim oIndexGP As Integer
'Scroll through each matrix item and see if it is a non stock item
For oIndexGP = 1 To uiMatrixGP.RowCount
Dim oEdit As SAPbouiCOM.EditText
uiEditText = uiMatrixGP.Columns.Item("3").Cells.Item(oIndexGP).Specific
uItemCode = uiEditText.String
oEdit = uiColumns.Item("3").Cells.Item(oIndexGP).Specific
'//we set it to 0 first to make sure it updates
oEdit.Value = 0
oEdit.Value = uItemCode
Next
uibutton = oFormGrossProfit.Items.Item("1").Specific
If UCase$(uibutton.Caption) = "UPDATE" Then
oFormGrossProfit.Items.Item("1").Click()
End If
If UCase$(uibutton.Caption) = "OK" Then
oFormGrossProfit.Items.Item("1").Click()
End If
oFormGrossProfit.Close()
'Unload all objects.
oFormGrossProfit = Nothing
oItemRecSet = Nothing
GC.Collect()
End If
Next
End If
End If
End If
End Sub