Skip to Content
0
Former Member
Jul 27, 2007 at 10:02 AM

et_FORM_DATA_ADD, problem in getting Line object

44 Views

Hi,

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

        Try
            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)
                            Doc.Browser.GetByKeys(BusinessObjectInfo.ObjectKey)

                            DocEntry = Doc.DocEntry
                            DocNum = Doc.DocNum

                            Lines = Doc.Lines

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

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

                                Item = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
                                'Item.Browser.GetByKeys(ItemCode)
                                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
                                ItemPrice.SetCurrentLine(1)
                                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'"
                                oRecSetLines.DoQuery(sSQLtext)

                                If oRecSetLines.RecordCount = 1 Then
                                    'Get the MinPrice here
                                    oRecSetLines.MoveFirst()
                                    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
                                Else
                                    SBO_Application.MessageBox("Error.")
                                End If
                            Next

                            Doc.Update()

                    End Select
                End If
            Else

            End If
        Catch ex As Exception
        End Try

    End Sub