Hi guys,
[I have posted this on other forum but didn’t get any help yet]
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:
Where “wsNAV_SalesHeaderAndLines” is a reference to a page wb service with a sales header and a sales line repeater linked to the sales header
Private Sub UpdateSalesLine()
Dim _SalesOrder As New wsNAV_SalesHeaderAndLines.wsNAV_SalesHeaderAndLines_Service
Dim salesOrder As New wsNAV_SalesHeaderAndLines.wsNAV_SalesHeaderAndLines
_SalesOrder.UseDefaultCredentials = False
_SalesOrder.Credentials = New System.Net.NetworkCredential(“wservice”, “aOer00%9”)
Try
salesOrder = _SalesOrder.Read(“1”, “P-20-B”) ’ va chercher la commande dans laquelle il faut travailler
Dim salesLines(0) As wsNAV_SalesHeaderAndLines.WS_SalesLine 'crée un array vide pour mettre les lignes
If Not salesOrder.WS_SalesLine Is Nothing Then
salesLines = salesOrder.WS_SalesLine
End If
If Not _SalesOrder.IsUpdated(salesOrder.Key) Then ’ s’assure que l’objet et encore parreil
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) ’ ajuste les valeurs
.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) ’ mets à jour le tout.
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub