I appreciate your help! sadly that is what I have. I moved OrderLineKey to the top and it does create the invoice but unlinked to the sales order. I tested having OrderLineKey be the only setvalue line but that gave me all the "item code is required" errors.
retVal = oInvLines.AddLine()
retval = oInvLines.SetValue("OrderLineKey$", OrderLineKey)
retval = oInvLines.SetValue("ItemCode$", ItemCode)
retval = oInvLines.SetValue("ItemCodeDesc$", ItemDesc)
retVal = oInvLines.GetValue("LineKey$",InvLineKey)
retVal = oInvLines.GetValue("InvoiceNo$",InvoiceNo)
retval = oInvLines.SetValue("OrderWarehouse$", Whse)
retval = oInvLines.SetValue("SOHistoryDetlSeqNo$", HistorySeq)
retval = oInvLines.SetValue("PromiseDate$", PromiseDate)
retval = oInvLines.SetValue("AppliedSalesOrderNo$", SONum)
retval = oInvLines.SetValue("QuantityShipped", QtyOrd)
retval = oInvLines.SetValue("QuantityOrdered", QtyOrd)
retval = oInvLines.SetValue("UnitPrice", UnitPrice)
retVal = oInvLines.Write()
------------------------------
Kate Krueger
Consultant
MicroAccounting
214.800.5555x553
------------------------------
Original Message:
Sent: 09-06-2024 19:10
From: Kevin Moyes
Subject: Script Sales Order to Invoice - OrderLineKey won't cooperate
100%, you have to set OrderLineKey first. Do not set the ItemCode. Doing this will absolutely create a new line, unlinked to the SO... and you can't retroactively link a new line to an SO line. The new line must start from the OrderLineKey.
Your first oInvLines.SetValue needs to be OrderLineKey.
------------------------------
Kevin Moyes
Technical Systems Analyst
Munjal White Consulting Co.
Toronto ON
------------------------------
Original Message:
Sent: 09-06-2024 18:57
From: Kate Krueger
Subject: Script Sales Order to Invoice - OrderLineKey won't cooperate
This is what breaks my brain - when I add in the debugging, everything reports that it is happy - retVal = 1 across the board. and technically that is true, it is writing everything except it skips the OrderLineKey, debugging on that setvalue specifically is still 1. I've wandered down some rabbit holes trying to just get that field to write!
------------------------------
Kate Krueger
Consultant
MicroAccounting
214.800.5555x553
Original Message:
Sent: 09-06-2024 18:49
From: Kevin Moyes
Subject: Script Sales Order to Invoice - OrderLineKey won't cooperate
I'm thinking it might be that the SO is not in an editable state (allowing you to create an invoice from it) during the post-write event, blocking things at a higher level. Did you check the retVal when setting the SO#? Perhaps add debug comments script-line by script-line to see where in the line reading / writing that things are breaking down.
------------------------------
Kevin Moyes
Technical Systems Analyst
Munjal White Consulting Co.
Toronto ON
Original Message:
Sent: 09-06-2024 18:39
From: Kate Krueger
Subject: Script Sales Order to Invoice - OrderLineKey won't cooperate
Thanks for your reply Kevin! I'm thinking this may be the same issue that I was having with CopyLinesFromSalesOrder. When I take out all the SetValue on Item Code, Qty Ordered, etc. I get the error message "The Item Code is Required, The Item Type is required" etc. If I re-open the sales order and run the script again it works perfectly to create the invoice. So I'm thinking the OrderLineKey won't write because at that moment in time, the sales order doesn't have an OrderLinekey written to the table. The script is running on table post-write but I don't think the sales order is all the way written. Is there a method to complete the write and re-open the sales order?
------------------------------
Kate Krueger
Consultant
MicroAccounting
214.800.5555x553
Original Message:
Sent: 09-06-2024 18:21
From: Kevin Moyes
Subject: Script Sales Order to Invoice - OrderLineKey won't cooperate
Don't SetValue on ItemCode to start the new invoice line... set the OrderLineKey... which should pull in the ItemCode.
Think about how VI imports of invoice lines work, when invoicing an SO. You don't import the fields that should flow from the SO lines.
------------------------------
Kevin Moyes
Technical Systems Analyst
Munjal White Consulting Co.
Toronto ON