Script to Loop through Invoice History Lines

Hello,

I was hoping to get some advice on scripting the BOI via a Button script that was placed on S/O Invoice Data Entry that would act as a "Quick Tax Credit" button. We use a third party cloud vendor to calculate our taxes but that shouldn't affect too much with here.

Essentially the prerequisite steps would be that the accounting personnel would:

  1. Create a new invoice
  2. Change the Invoice Type to "Credit Memo"
  3. Type in the customer's number
  4. Type in the original invoice number into the "Apply To Inv No" field
  5. Click the button script

The button script would then find the associated invoice from the "ApplyTo" field in AR_InvoiceHistoryDetail and loop through each line and processing it twice on the CM. For each line in the original invoice it would:

  1. Copy over the item code (but skip all comment item class/types) into 2 lines in the CM.
  2. Copy over the quantity. But for the 2nd line, the quantity would be (qty * -1) to reverse the line above it. This essentially adds then removes the item from inventory as a wash.
  3. Copy over the warehouse code
  4. For the 2nd line, it would change the tax class to 'NT'...
    This allows the CM to credit the tax from the first line and ignore the tax from the 2nd line.
    This also ensures that the subtotal is still $0 because the { ExtendedPrice + ( ExtendedPrice * -1 ) = 0 }. So the only net would be the taxable portions.
  5. For the first line, add a comment stating "Reversed Taxable Line"
  6. For the second line, add a comment stating "Converted line to Non-Taxable / Exempt"

I've dealt with vb button scripts in the past, but the detail tables are what stumps me (both looping in history and also adding it to the current CM).

I assume I would need to get the table via:

Set oInvHistDtl = oSession.AsObject(oSession.GetObject("AR_InvoiceHistoryDetail_Svc"))

But I typically have used .Find() which I believe is only to retrieve single records, which isn't what I need for a detail table.

Would someone be kind enough to help me?

  • 0

    I'd start with the invoice history header table / service object, and a browse filter.  Loop through the results for that invoice#, confirm the invoice type and customer # matches (because technically the invoice number can be re-used... saved to history with a different HeaderSeqNo).

    Then, when you are sure you're in the right invoice header, grab the lines object from there and loop...