Reputation: 1003
I am trying to create purchase invoice:
PurchseInvoice_Service pis = new PurchseInvoice_Service();
PurchseInvoice pi = new PurchseInvoice();
pis.Create(ref pi);
pi.Buy_from_Vendor_No = "40000";
pi.Currency_Code = "EUR";
pi.Location_Code = "GREEN";
pis.Update(ref pi);
pi.PurchLines = new Purch_Invoice_Line[1];
pi.PurchLines[0] = new Purch_Invoice_Line();
pi.PurchLines[0].Type = PurchaseInvoice.Type.Item;
pi.PurchLines[0].No = "LS-150";
pi.PurchLines[0].Quantity = 1;
pi.PurchLines[0].Unit_of_Measure_Code = "PCS";
pi.PurchLines[0].Line_Amount = 1;
pis.Update(ref pi);
And I am getting SoapException
with the message on the last line:
Standard Text Code 'LS-150' does not exist.
I am strongly confused, this item code is used in the purchase order and I can see it on the item list. So why I cannot use it here? This should work in my opinion. I can even access this text ID from the 'PostOrder
' object:
Console.WriteLine( po.PurchLines[1].No );
Output is : LS-150
I use Dynamics NAV 2009 R2
with DEMO
application for the "CRONUS International Ltd.
" company - maybe that is my problem about?
BTW. What is the story with this constant SQL Server timeouts? Why I can create PurchaseInvoice
which cannot be deleted due to not existence and cannot be updated due to wrong format, but I can read them nicely? Aren't the web services supposed to be 'The Safe Way To Access Application'?
SOLUTION:
Solution was to add one update line:
....
pi.PurchLines[0] = new Purch_Invoice_Line();
pis.Update(ref pi);
pi.PurchLines[0].Type = PurchaseInvoice.Type.Item;
....
Thanks to @uncommonsense.
Upvotes: 2
Views: 1059
Reputation: 712
Be sure to set the Type field of the Purchase Line as well, i.c. to option value "Item". The default option value " " (blank) means the purchase line is a text line, in which case the "No." field can be used to look up a standard text (which, from NAV's perspective, is what your code above is doing, hence the error message).
Upvotes: 2