Showing results for 
Search instead for 
Did you mean: 

et_FORM_DATA_ADD, problem in getting Line object

Former Member
0 Kudos


This is my first time using the et_FORM_DATA_ADD event. Objective: upon Add the Quotation, check each UnitPrice in the Document line. Problem: unable to get the children (lines) object from the parent (Documents) object. The For - Next loop is always skipped. Anybody can point out the problem? Appreciate your help. Below is the code.

        Private Sub SBO_Application_FormDataEvent(ByRef BusinessObjectInfo As SAPbouiCOM.BusinessObjectInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.FormDataEvent

            If BusinessObjectInfo.BeforeAction Then
                If BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD Then
                    Select Case BusinessObjectInfo.Type
                        'Case SAPbobsCOM.BoObjectTypes.oOrders.ToString
                        Case SAPbobsCOM.BoObjectTypes.oQuotations
                            Dim Doc, Doc1 As SAPbobsCOM.Documents
                            Dim Lines As SAPbobsCOM.Document_Lines
                            Dim DocEntry, DocNum, LineNum, ItemCode, sErrMsg As String
                            Dim UnitPrice, MinPrice As String
                            Dim i, j As Integer
                            Dim bRetVal As Boolean
                            Dim lErrCode As Long

                            Doc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oQuotations)

                            DocEntry = Doc.DocEntry
                            DocNum = Doc.DocNum

                            Lines = Doc.Lines

                            For i = 0 To Lines.Count - 1
                                ItemCode = Lines.ItemCode
                                UnitPrice = Lines.UnitPrice

                                Dim Item As SAPbobsCOM.Items
                                Dim ItemPrice As SAPbobsCOM.Items_Prices

                                Item = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
                                bRetVal = Item.GetByKey(ItemCode)
                                If Not bRetVal Then
                                    oCompany.GetLastError(lErrCode, sErrMsg)
                                    SBO_Application.MessageBox("Failed to Retrieve the record " & lErrCode & " " & sErrMsg)
                                    Exit Sub
                                End If
                                ItemPrice = Item.PriceList
                                MinPrice = ItemPrice.Price

                                If UnitPrice < MinPrice Then
                                    Lines.UserFields.Fields.Item("U_Approve").Value = "TRUE"
                                End If

                                Dim oRecSetLines As SAPbobsCOM.Recordset
                                Dim sSQLtext As String

                                oRecSetLines = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                                sSQLtext = "SELECT Price FROM ITM1 WHERE ItemCode = '" & ItemCode & "' AND PriceList = '2'"

                                If oRecSetLines.RecordCount = 1 Then
                                    'Get the MinPrice here
                                    MinPrice = oRecSetLines.Fields.Item(0).Value

                                    If CDbl(oRecSetLines.Fields.Item(0).Value) < CDbl(UnitPrice) Then
                                        'Price below MinPrice, write QUT1.U_Approve --> change to write file

                                        Doc.UserFields.Fields.Item("U_Approve").Value = "TRUE"
                                        Lines.UserFields.Fields.Item("U_Approve").Value = "TRUE"

                                    End If
                                End If


                    End Select
                End If

            End If
        Catch ex As Exception
        End Try

    End Sub

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Are you shure the business object does already exist in db on et_FORM_DATA_ADD beforeAction (Does getByKey return true)? Do DocNum and DocEntry make sense?

Maybe you change

If BusinessObjectInfo.BeforeAction Then


If Not BusinessObjectInfo.BeforeAction Then

or does that affect your idea of approving?

Answers (1)

Answers (1)

Former Member
0 Kudos

I tried both BusinessObjectInfo.BeforeAction = TRUE and BusinessObjectInfo.BeforeAction = FALSE, but result is same. With that code, actually managed to get the value of DocNum and DocEntry but somehow unable to get the lines/child object.

I think the problem is with this code:

DocEntry = Doc.DocEntry

DocNum = Doc.DocNum

Lines = Doc.Lines

If I set the breakpoint at Lines = Doc.Lines, I can get the value of DocEntry and DocNum, but somehow unable to retrieve Lines/child object.