Skip to Content
avatar image
Former Member

[SAP B1 DI API] Service Contract lines order

Hi,

I have an add-on which allow to renew automatically one or multiple service contracts by DIAPI.

This is my items tab. I added a second grid which shows the detail of the upper grid clicked line. The relation between the 2 grids is the line number and the contractID.

As you see, the column "Total Valor" (total value) from the upper grid is different from the grid bellow and there is my problem. In my database i have the following line order (CTR1)

I would like to know why SAP doesnt follow the order from the database field "Line".

Like I said, I have a relation between the line and contractID, so if the grid line order isnt right, when i click at the row i will get the wrong line detail.

Thank You

Add comment
10|10000 characters needed characters exceeded

  • Former Member DIEGO LOTHER

    I have 2 contracts (1 created with the SAP form and other with DI API) with the same data at the database (same line order) but in the form it appears with different order.

    Thank you

    s1.png (6.9 kB)
    s2.png (6.7 kB)
    s1-1.png (24.6 kB)
    s2-1.png (29.2 kB)
  • Could you share the code where you add your contract using DI API?

  • Former Member Danilo Kasparian
      Dim oContractNew As SAPbobsCOM.ServiceContracts = SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oServiceContracts)
            Dim oContractOld As SAPbobsCOM.ServiceContracts = SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oServiceContracts)
            With DataTable(enDatatable.cst_mtxContratos)
                oContractOld.GetByKey(.GetValue("ContractID", iLine))
                oContractNew.CustomerCode = .GetValue("CstmrCode", iLine).ToString
                oContractNew.CustomerName = .GetValue("CstmrName", iLine).ToString
                oContractNew.ContactCode = oContractOld.ContactCode
                oContractNew.Remarks = oContractOld.Remarks
                oContractNew.UserFields.Fields.Item("U_SEI_Observacoes").Value = oContractOld.UserFields.Fields.Item("U_SEI_Observacoes").Value
                oContractNew.StartDate = DateAdd(DateInterval.Day, 1, .GetValue("EndDate", iLine))
                oContractNew.EndDate = DateAdd(DateInterval.Day, -1, GetEndDate(.GetValue("StartDate", iLine).ToString, DateAdd(DateInterval.Day, 1, .GetValue("EndDate", iLine)).Date))
                oContractNew.UserFields.Fields.Item("U_SEI_Valor").Value = oContractOld.UserFields.Fields.Item("U_SEI_Valor").Value
                oContractNew.UserFields.Fields.Item("U_SEI_DescAcerto").Value = oContractOld.UserFields.Fields.Item("U_SEI_DescAcerto").Value
                oContractNew.UserFields.Fields.Item("U_SEI_DescComercial").Value = oContractOld.UserFields.Fields.Item("U_SEI_DescComercial").Value
                oContractNew.UserFields.Fields.Item("U_SEI_ValorCAcerto").Value = oContractOld.UserFields.Fields.Item("U_SEI_ValorCAcerto").Value
                oContractNew.UserFields.Fields.Item("U_SEI_ValorFinal").Value = oContractOld.UserFields.Fields.Item("U_SEI_ValorFinal").Value
                oContractNew.UserFields.Fields.Item("U_SEI_MoradaEntrega").Value = oContractOld.UserFields.Fields.Item("U_SEI_MoradaEntrega").Value
                oContractNew.UserFields.Fields.Item("U_SEI_Localizacao").Value = oContractOld.UserFields.Fields.Item("U_SEI_Localizacao").Value
                oContractNew.ContractType = oContractOld.ContractType
                oContractNew.ServiceBPType = SAPbobsCOM.ServiceTypeEnum.srvcSales
                oContractNew.ServiceType = oContractOld.ServiceType
                Dim mesesDif As Integer = MonthDifference(oContractOld.UserFields.Fields.Item("U_SEI_DataExecucao").Value.ToString, .GetValue("StartDate", iLine).ToString)
                Dim dataExec As Date = .GetValue("EndDate", iLine).ToString
                If (oContractOld.Status <> SAPbobsCOM.BoSvcContractStatus.scs_Terminated) Then
                    oContractNew.Renewal = SAPbobsCOM.BoYesNoEnum.tYES
                    oContractNew.ReminderTime = oContractOld.ReminderTime
                    oContractNew.Status = SAPbobsCOM.BoSvcContractStatus.scs_Draft
                Else
                    oContractNew.TerminationDate = DateAdd(DateInterval.Day, 1, oContractNew.StartDate)
                    oContractNew.Status = SAPbobsCOM.BoSvcContractStatus.scs_Terminated
                    oContractNew.Renewal = SAPbobsCOM.BoYesNoEnum.tNO
                End If
                oContractNew.UserFields.Fields.Item("U_SEI_DataExecucao").Value = dataExec.AddMonths(mesesDif).Date.ToString
                oContractNew.UserFields.Fields.Item("U_SEI_NDeslocacoes").Value = oContractOld.UserFields.Fields.Item("U_SEI_NDeslocacoes").Value
                'oContractNew.UserFields.Fields.Item("U_SEI_NTecnicos").Value = oContractOld.UserFields.Fields.Item("U_SEI_NTecnicos").Value
                oContractNew.UserFields.Fields.Item("U_SEI_TotalDeslocacao").Value = oContractOld.UserFields.Fields.Item("U_SEI_TotalDeslocacao").Value
                oContractNew.UserFields.Fields.Item("U_SEI_TotalPecas").Value = oContractOld.UserFields.Fields.Item("U_SEI_TotalPecas").Value
                oContractNew.UserFields.Fields.Item("U_SEI_RefContrato").Value = oContractOld.UserFields.Fields.Item("U_SEI_RefContrato").Value
                oContractNew.UserFields.Fields.Item("U_SEI_Navision").Value = oContractOld.UserFields.Fields.Item("U_SEI_Navision").Value
                oContractNew.UserFields.Fields.Item("U_SEI_DescMorada").Value = oContractOld.UserFields.Fields.Item("U_SEI_DescMorada").Value
            End With
            With oContractNew.Lines
                For i = 1 To oContractOld.Lines.Count
                    .ItemCode = oContractOld.Lines.ItemCode
                    .ManufacturerSerialNum = oContractOld.Lines.ManufacturerSerialNum
                    '.InternalSerialNum = oContractOld.Lines.InternalSerialNum
                    .UserFields.Fields.Item("U_SEI_Valor").Value = oContractOld.Lines.UserFields.Fields.Item("U_SEI_Valor").Value
                    .UserFields.Fields.Item("U_SEI_Cancelado").Value = oContractOld.Lines.UserFields.Fields.Item("U_SEI_Cancelado").Value
                    If (i < oContractOld.Lines.Count) Then
                        .Add()
                        oContractOld.Lines.SetCurrentLine(i)
                    End If
                Next
            End With
            oContractNew.UserFields.Fields.Item("U_SEI_ContratoOrigem").Value = oContractOld.ContractID
            oContractNew.Add()
  • Get RSS Feed

1 Answer

  • Jun 27, 2017 at 07:03 PM

    Hi

    Try to do like this, the lines sometimes it is a little bit tricky, so I used set current line when reading/adding

            With oContractNew.Lines
                For i = 0 To oContractOld.Lines.Count -1
                    oContractOld.Lines.SetCurrentLine(i)
    
                    .ItemCode = oContractOld.Lines.ItemCode
                    .ManufacturerSerialNum = oContractOld.Lines.ManufacturerSerialNum
                    '.InternalSerialNum = oContractOld.Lines.InternalSerialNum
                    .UserFields.Fields.Item("U_SEI_Valor").Value = oContractOld.Lines.UserFields.Fields.Item("U_SEI_Valor").Value
                    .UserFields.Fields.Item("U_SEI_Cancelado").Value = oContractOld.Lines.UserFields.Fields.Item("U_SEI_Cancelado").Value
                   
                    .Add()
                    .SetCurrentLine(.Lines.Count - 1)
                Next
            End With
    Add comment
    10|10000 characters needed characters exceeded