Overriding tax to AR Invoice object

SUGGESTED

I'm trying to override the tax on the AR Invoice object, and while I'm successful at changing the amount on the AR Invoice Header, I'm having trouble changing the amount on the AR Invoice Tax Summary. Here's my code which fires on Post-Write of AR Invoice Header table:

calcResult = 1.23

set TaxSummary = oSession.AsObject(oSession.GetObject("AR_InvoiceTaxSummary_bus"))

retval = TaxSummary.SetKeyValue("InvoiceNo$", orderNo)
retval = TaxSummary.SetKeyValue("InvoiceType$", invoiceType)
retval = TaxSummary.SetKeyValue("ScheduleSeqNo$", "000001")
retval = TaxSummary.SetKeyValue("TaxCode$", "SOVOS")
retval = TaxSummary.SetKey()
retVal = TaxSummary.SetValue("SalesTaxAmt", CDbl(calcResult))
retVal = TaxSummary.SetValue("TaxableSalesAmt", trxAmt)
retVal = TaxSummary.SetValue("Overridden$","Y")
retval = TaxSummary.Write()

'confirm that the values have been written
retval = TaxSummary.SetKeyValue("InvoiceNo$", orderNo)
retval = TaxSummary.SetKeyValue("InvoiceType$", invoiceType)
retval = TaxSummary.SetKeyValue("ScheduleSeqNo$", "000001")
retval = TaxSummary.SetKeyValue("TaxCode$", "SOVOS")
retval = TaxSummary.SetKey()
taxAmt = 0.00
overridden = ""
retVal = TaxSummary.GetValue("SalesTaxAmt", taxAmt)
retVal = TaxSummary.GetValue("Overridden$", overridden)
If oSession.UI > 0 Then oSession.AsObject(oSession.UI).MessageBox "", "the tax amount on the tax summary object is " & cstr(taxAmt) & "|" & overridden

When I put a message box at the end of the function to pause any other script execution from Sage, and look at the back end using an ODBC connection, I see the value updated:

But after I continue script execution, and the screen clears, Overridden is set back to N and SalesTaxAmt back to zero.

Any ideas on what I'm doing wrong?

  • 0
    SUGGESTED

    You're likely running into a similar issue as the one in your post regarding the sales order tax records.

    https://www.sagecity.com/support_communities/sage100_erp/f/sage-100-business-object-interface/150566/updating-salesorder-tax-records

    Refer to https://help-sage100.na.sage.com/2020/FLOR/#Object_Reference/AR/AR_Invoice_bus.html and you'll see the AR invoice bus object also has a SalesTaxCalcObj property which you should attempt to use instead of getting a new handle to the tax object and risk clashing with the already in memory object. I don't recall seeing a follow up from you on your other post but if you got it working using the SalesTaxCalcObj, then you should try to apply it here as well.

  • 0 in reply to David Speck

    I was able to get the other one working by moving my code in the original post from Sales Order Header Pre-Write to Sales Order Post-Write. I wasn't having a lot of success overriding the SalesTaxCalcObj and ended up not using it (I think things broke when I tried to use SalesTaxCalcObj in the post-write).

    In this current scenario, I tried keeping my AR Invoice Header Post-Write code, but overriding the SalesTaxCalcObj in the Pre-Write, but to no avail:

    Set oSalesTaxCalcObj = oSession.AsObject(oBusObj.SalesTaxCalcObj)
    
    invoiceNo = ""
    invoiceType = ""
    
    retVal = oBusObj.GetValue("InvoiceNo$", invoiceNo)
    retVal = oBusObj.GetValue("InvoiceType$", invoiceType)
    
    retval = oSalesTaxCalcObj.SetKeyValue("InvoiceNo$", invoiceNo)
    retval = oSalesTaxCalcObj.SetKeyValue("InvoiceType$", invoiceType)
    retval = oSalesTaxCalcObj.SetKeyValue("ScheduleSeqNo$", "000001")
    retval = oSalesTaxCalcObj.SetKeyValue("TaxCode$", "SOVOS")
    retval = oSalesTaxCalcObj.SetKey()
    
    retVal = oSalesTaxCalcObj.SetValue("SalesTaxAmt", 2.46)
    retVal = oSalesTaxCalcObj.SetValue("Overridden$", "Y")
    retval = oSalesTaxCalcObj.Write()

    What's so weird to me about this is I'm seeing the data change when I query the ODBC, but then it reverts back to zero at the end of the function. Why doesn't the AR Invoice Tax Summary Post-Write function fire off when this happens?