Skip to Content
0
Mar 19, 2021 at 01:05 AM

DI API error adding Special Prices

128 Views Last edit Mar 21, 2021 at 05:20 PM 2 rev

Good afternoon.

Using DI API I made a macro in Excel to add prices by period and quantity. In a test database it works correctly but in the production base, with the same price lists and items as the test database, it does not work.

On the line

Retval = oPL.Add 

I am getting the error message "234109417 - Different asset value on other lines" and there is no price per period and quantity for the item. I hope you can support me by indicating where I can look for the cause of the error since both databases are "identical".

This is my code:

row = 2
    Do While ActiveSheet.Cells(row, 1) <> ""
        Set oPL = oCompany.GetBusinessObject(oSpecialPrices)
        ' Actualización por periodo y cantidad de la lista at poniendo en cantidad una caja y el % de descuento por pieza
        If (oPL.GetByKey(ActiveSheet.Cells(row, 1), "*3") = True) Then
            oPL.ItemCode = ActiveSheet.Cells(row, 1)
            oPL.PriceListNum = 3
            oPL.SpecialPricesDataAreas.SetCurrentLine (0)
            oPL.SpecialPricesDataAreas.DateFrom = ActiveSheet.Cells(3, 11)
            oPL.SpecialPricesDataAreas.Dateto = ActiveSheet.Cells(4, 11)
            oPL.SpecialPricesDataAreas.Discount = ActiveSheet.Cells(row, 9)
            oPL.SpecialPricesDataAreas.PriceListNo = 3
            If ((oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Count) > 0) Then
                oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SetCurrentLine (0)
            Else
                oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Add
            End If
            oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Quantity = ActiveSheet.Cells(row, 7)
            oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SpecialPrice = ActiveSheet.Cells(row, 5)
            Retval = oPL.Update()
            If Retval <> 0 Then
                ActiveSheet.Cells(row, 12) = oCompany.GetLastErrorDescription()
            Else
                ActiveSheet.Cells(row, 12) = " - Actualizado -" & oPL.ItemCode
            End If
        Else
            oPL.ItemCode = ActiveSheet.Cells(row, 1)
            oPL.PriceListNum = 3
            Retval = oPL.Add
            If Retval <> 0 Then
                    ActiveSheet.Cells(row, 13) = oCompany.GetLastErrorDescription()
                Else
                    ActiveSheet.Cells(row, 13) = " - Addedado -" & oPL.ItemCode
            End If
            Set oPL = oCompany.GetBusinessObject(oSpecialPrices)
            If (oPL.GetByKey(ActiveSheet.Cells(row, 1), "*3") = True) Then
                oPL.SpecialPricesDataAreas.Add
                oPL.SpecialPricesDataAreas.SetCurrentLine (0)
                oPL.SpecialPricesDataAreas.PriceListNo = 3
                oPL.SpecialPricesDataAreas.DateFrom = ActiveSheet.Cells(3, 11)
                oPL.SpecialPricesDataAreas.Dateto = ActiveSheet.Cells(4, 11)
                oPL.SpecialPricesDataAreas.Discount = ActiveSheet.Cells(row, 9)
                If ((oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Count) > 0) Then
                     oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SetCurrentLine (0)
                Else
                     oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Add
                End If
                oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Quantity = ActiveSheet.Cells(row, 7)
                oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SpecialPrice = ActiveSheet.Cells(row, 5)
                Retval = oPL.Update()
                If Retval <> 0 Then
                    ActiveSheet.Cells(row, 12) = oCompany.GetLastErrorDescription()
                Else
                    ActiveSheet.Cells(row, 12) = " - Agregado -" & oPL.ItemCode
                End If
            End If
        End If
        row = row + 1
    Loop
    
    row = 2
    Do While ActiveSheet.Cells(row, 1) <> ""
        Set oPL = oCompany.GetBusinessObject(oSpecialPrices)
        'Actualización por periodo y cantidad la lista Z
        If (oPL.GetByKey(ActiveSheet.Cells(row, 1), "*2") = True) Then
            oPL.ItemCode = ActiveSheet.Cells(row, 1)
            oPL.PriceListNum = 2
            oPL.SpecialPricesDataAreas.SetCurrentLine (0)
            oPL.SpecialPricesDataAreas.DateFrom = ActiveSheet.Cells(3, 11)
            oPL.SpecialPricesDataAreas.Dateto = ActiveSheet.Cells(4, 11)
            oPL.SpecialPricesDataAreas.Discount = ActiveSheet.Cells(row, 9)
            oPL.SpecialPricesDataAreas.PriceListNo = 2
            If ((oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Count) > 0) Then
                oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SetCurrentLine (0)
            Else
                oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Add
            End If
            oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Quantity = ActiveSheet.Cells(row, 7)
            oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SpecialPrice = ActiveSheet.Cells(row, 4)
            Retval = oPL.Update()
            If Retval <> 0 Then
                ActiveSheet.Cells(row, 12) = oCompany.GetLastErrorDescription()
            Else
                ActiveSheet.Cells(row, 12) = " - Actualizado -" & oPL.ItemCode
            End If
        Else
            oPL.ItemCode = ActiveSheet.Cells(row, 1)
            oPL.PriceListNum = 2
            Retval = oPL.Add
            If Retval <> 0 Then
                    ActiveSheet.Cells(row, 14) = oCompany.GetLastErrorDescription()
                Else
                    ActiveSheet.Cells(row, 14) = " - Addedado -" & oPL.ItemCode
            End If
            Set oPL = oCompany.GetBusinessObject(oSpecialPrices)
            If (oPL.GetByKey(ActiveSheet.Cells(row, 1), "*2") = True) Then
                oPL.SpecialPricesDataAreas.Add
                oPL.SpecialPricesDataAreas.SetCurrentLine (0)
                oPL.SpecialPricesDataAreas.PriceListNo = 2
                oPL.SpecialPricesDataAreas.DateFrom = ActiveSheet.Cells(3, 11)
                oPL.SpecialPricesDataAreas.Dateto = ActiveSheet.Cells(4, 11)
                oPL.SpecialPricesDataAreas.Discount = ActiveSheet.Cells(row, 9)
                If ((oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Count) > 0) Then
                     oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SetCurrentLine (0)
                Else
                     oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Add
                End If
                oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.Quantity = ActiveSheet.Cells(row, 7)
                oPL.SpecialPricesDataAreas.SpecialPricesQuantityAreas.SpecialPrice = ActiveSheet.Cells(row, 4)
                Retval = oPL.Update()
                If Retval <> 0 Then
                    ActiveSheet.Cells(row, 12) = oCompany.GetLastErrorDescription()
                Else
                    ActiveSheet.Cells(row, 12) = " - Agregado -" & oPL.ItemCode
                End If
            End If
        End If
        row = row + 1
    Loop
    
  End If
  MsgBox ("Proceso terminado, se actualizaron " & row - 2 & " Precios.")
  oCompany.Disconnect