Quantcast
Channel: NAV Three Tier — mibuso.com
Viewing all articles
Browse latest Browse all 10032

Dynamics NAV 2015 Update Sales Line by Web service : Line already exists

$
0
0
Hi guys,
I'm building some data synchronization using Dynamics NAV web service. I managed to create Sales Header and Sales Lines, but When I try to update a sales Line I got this message :
The Sales Lines Exists, Identifiation fields and values: Document Type = 'Order', Document No.='P-20-B',Line No.=10 000

from what i understand it seems to be trying to recreate the line instead of doing an update. I'm stuck can you help me?

Here's my test code:
Private Sub UpdateSalesLine()
        Dim _SalesOrder As New wsNAV_SalesHeaderAndLines.wsNAV_SalesHeaderAndLines_Service ' this is the Sales Header Service
        Dim salesOrder As New wsNAV_SalesHeaderAndLines.wsNAV_SalesHeaderAndLines  ' this is the Sales Header card
        _SalesOrder.UseDefaultCredentials = False
        _SalesOrder.Credentials = New System.Net.NetworkCredential("username", "password")

        Try
            salesOrder = _SalesOrder.Read("1", "P-20-B") ' get the Sales Header Card

            Dim salesLines(0) As wsNAV_SalesHeaderAndLines.WS_SalesLine ' Create an empty array

            If Not salesOrder.WS_SalesLine Is Nothing Then
                salesLines = salesOrder.WS_SalesLine
            End If


            If Not _SalesOrder.IsUpdated(salesOrder.Key) Then ' check if object is still the same


                Dim idx As Integer = 0
                Dim blnLineFound As Boolean = False
                While idx < salesLines.Length
                    Dim oLine As wsNAV_SalesHeaderAndLines.WS_SalesLine
                    oLine = DirectCast(salesLines(idx), wsNAV_SalesHeaderAndLines.WS_SalesLine)
                    If oLine.Line_No = 10000 Then
                        blnLineFound = True
                        Exit While
                    End If
                    idx = idx + 1
                End While

                If blnLineFound Then

                    With DirectCast(salesLines(idx), wsNAV_SalesHeaderAndLines.WS_SalesLine) ' set values
                        .Bin_Code = Nothing
                        .Description = "1 - W 24 X 32 x 17 *2"
                        .Description_2 = Nothing

                        .Document_No = "P-20-B"
                        '.Document_Type = wsNAV_SalesHeaderAndLines.Document_Type_1.Order
                        '.Document_TypeSpecified = True
                        .Item_Category_Code = "PF"
                        .Key = Nothing
                        '.Line_No = 10000
                        '.Line_NoSpecified = True

                        .Location_Code = "COATICOOK"
                        .Type = wsNAV_SalesHeaderAndLines.Type.Item
                        .TypeSpecified = True

                        .No = "GCAISSON"
                        .Product_Group_Code = "CABINETS"
                        .Quantity = 1
                        .QuantitySpecified = True


                        .Unit_Price = 10000
                        .Unit_PriceSpecified = True
                        .Variant_Code = Nothing

                    End With
                End If

                _SalesOrder.Update(salesOrder) ' update Sales Header Card

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

Viewing all articles
Browse latest Browse all 10032

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>