2

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.

shA.t
  • 16,580
  • 5
  • 54
  • 111
vt100
  • 923
  • 1
  • 11
  • 21

1 Answers1

2

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).

Jan Hoek
  • 702
  • 5
  • 13
  • Thanks, I added a line (which I forgot to copy from the code). Which option value are you talking about? I would love to change it, but I am not sure what you are referring to. I tried `pi.PurchLines[0].Type = PurchaseInvoice.Type._blank_` and `pi.PurchLines[0].Type = PurchaseInvoice.Type.Item` and there is still the same exception with the same message. Any ideas? :) – vt100 Apr 04 '13 at 08:47
  • What I don't understand is how Type.Item would be defined at PurchaseInvoice-level? It should come from PurchaseInvoiceLine-level, I suppose? Maybe, as a test, could you pass value 2 as the type of the purchase line? (since the zero-based option string is " ,G/L Account,Item,,Fixed Asset,Charge (Item)"). – Jan Hoek Apr 04 '13 at 09:39
  • PurchaseInvoiceLine has no such a member and object of this type has field `Type` which is `PurchaseInvoice.Type` - strange to me as well... I cast `pi.PurchLines[0].Type = (PurchaseInvoice.Type)2` now and it is the same. I tried other integers as well. No effects whatsoever... – vt100 Apr 04 '13 at 09:54
  • 1
    Thanks for your time :) I solved it by adding one more line with update just after creating the new `Purchase_Invoice_line` and before setting the `No` field. This does not make any sense to me but works :) Thanks again. – vt100 Apr 04 '13 at 10:08