Create Purchase Order Invoice via BOI

SOLVED

Experts,


I am able to create Sales Order, Sales Order Invoices, and AP Invoices via BOI without any issues. I am missing something about the order of things for PO Receipt of Invoice. Here is an excerpt of my code (it's in Powershell, but the methods are the same as you would use in VBScript or C#): I took out some of the not relevant logic and error handling to make it more readable.

$retVal = $oPOInv.nSetValue("ReceiptType$", "I")
$sRecNo = ""
$retVal = $oPOInv.nGetNextNextInvoiceEntryNo([ref]$sRecNo)
$retVal = $oPOInv.nSetKeyValue("ReceiptType$", "I")
$retVal = $oPOInv.nSetKeyValue("ReceiptNo$",[ref]$sRecNo)
$retVal = $oPOInv.nSetKey()
...
            
$retVal = $oPOInv.nSetValue("PurchaseOrderNo$",[ref]$sPONo)
...
$retVal = $oPOInv.nSetValue("InvoiceNo$",[ref]$sInv)
...
$retVal = $oPOInv.nSetValue("InvoiceDate$",[ref]$sInvoiceDate)
...
            
# Loop through the Line Items
...
$bLinesOkay = $true
foreach ($item in $xDoc.Invoice.LineItems)
{ 
    # Get PO Item Data for the line
    $sItemCode = $item.item.ItemNumber
    $nQty = [float]$item.item.Quantity
    $nAmount = [float]$item.item.Amount
    if ([string]::IsNullOrEmpty($item.item.GLAccount))
    {
        $sGLAccount = ''
    }
    else
    {
        $sGLAccount = $item.item.GLAccount
        $retVal = $oAccount.nFind("$sGLAccount")
        ...
        $retVal = $oAccount.nGetValue("AccountKey$",[ref]$sGLAccount)
    }
    $sOrderLineKey = $item.item.OrderLineKey
                    
    # Create and Write the line
    $retVal =$oPOInvLines.nAddLine()
    ...
    $retVal = $oPOInvLines.nSetValue("ItemCode$",[ref]$sItemCode)
    ...
    $retVal = $oPOInvLines.nSetValue("OrderLineKey$",[ref]$sOrderLineKey)
    ... 
    $retVal = $oPOInvLines.nSetValue("QuantityInvoiced",[ref]$nQty)
    ...
    $retVal = $oPOInvLines.nSetValue("ExtensionAmt",[ref]$nAmount)
    ...
}

All $retVal are fine up to when I set the ItemCode (I get a field is not in the I/O list error). When I only try to use the OrderLineKey$ I get a Missing or Invalid Header at the setval for the OrderLineKey$. 

The Sage version is v2014 and PO Invoice Entry has Batch Entry turned on. I am not 100% on setting the ReceiptType. The examples I saw only set it once with a SetValue in the beginning (I assume that is what Sage does when you open the Invoice task vs. the ROG task). I do it a second time as part of the SetKeyValue for the Invoice. If I don't it will error out on the SetKey().

Even so the nNextNextInvoiceEntryNo looks like a typo, it comes back with the next invoice no. So that piece works.

Any ideas what I am doing wrong?

Thanks,

Bastian

  • 0
    SUGGESTED

    For some strange reason, I think the field name is "ItemCodeDesc" in this object.  That's what it looks like in DFDM at least.

  • 0 in reply to hyanaga

    I didn't check in 2014, but in 2017 there is a field named ItemCode.  

  • +1
    verified answer

    When i deal with ROGs or ROIs, i don't manually add the lines the way you are.

    If you are doing an ROI vs an ROG, then GetNextNextInvoiceEntryNo should be the correct method to use to get the next invoice number since it is tracked separately from the next receipt number in the PO module's options.

    After setting up the receipt type and receipt/invoice number, i use SetValue on the PurchaseOrderNo followed by CopyFromPurchaseOrder with the PO # passed as the first and only argument, this sets up all the header fields to be copied from the PO.

    I then set any other header values i want to override followed by the CopyPurchaseOrderLines with either a 1 (to indicate to receive all lines in full) or a 0 (to indicate not to receive all lines in full). This is what the UI does when the user clicks on the lines tab and it asks if you want to receive everything in full. It sets up all the appropriate lines for you.

    You can then loop through the lines as needed to update the values you need to.