Script to add CC Fee to Invoice - getting an error!

SOLVED

I know there are several posts about adding a line to an invoice to charge a fee.  I've modified a script I found either here or in a Sage scripting class, but for some reason, I can't get it to work this time.

When I put it on the Pre-Write event, it doesn't update the Invoice total after the CC Fee line is added.  When I put it on Post-Write, I get an error "' 'SY_SalesTaxClass' does not have correct permissions" and does not save the changes.  

I'm very frustrated!  I have another script that adds a line on Pre-Write, but I can't do that for this script because we need to get the totals, including the Sales Tax Amount, in order to calculate the fee.

Can anyone see what is wrong in my script, or has a suggestion to fix this?  Here it is!

CCRate= .03 : ordertotal=0 : taxable=0 : nontaxable=0 : freight=0 : discount=0

ccfee=0 : salestax=0 : found=False : sItemCode = "" : ccOrig=0

retVal = oBusObj.GetValue("FreightAmt", freight)
retVal = oBusObj.GetValue("TaxableAmt", taxable)
retVal = oBusObj.GetValue("NonTaxableAmt", nontaxable)
retVal = oBusObj.GetValue("DiscountAmt", discount)
retVal = oBusObj.GetValue("SalesTaxAmt", salestax)

msgbox "freight = " & freight
msgbox "taxable = " & taxable
msgbox "nontaxable = " & nontaxable

ordertotal = freight+taxable+nontaxable+salestax-discount

ccfee = ordertotal * CCrate

If ccfee >0 Then

'First scroll through the lines to see if the fee is already there
Set oLines = oBusObj.AsObject(oBusObj.Lines) 'get handle to invoice detail object
oLines.MoveFirst()
Do While CBool(oLines.EOF) = False
retVal = oLines.GetValue("ItemCode$", sItemCode)

If sItemCode = "/CCFEE" Then

'Fee is found, update the line
retVal = oLines.GetValue("ExtensionAmt", ccOrig)
ordertotal = ordertotal - ccOrig
msgbox "ordertotal = " & ordertotal
ccfee = ordertotal * CCrate
msgbox "cc fee " & ccfee
retVal = oLines.SetValue("ExtensionAmt", ccfee)
retWrite = oLines.Write()
found=True
If retWrite <> 0 Then
' Just fall through
Exit Do
End If 'retWrite
End If 'item code
retVal = oLines.MoveNext()
Loop
msgbox found

'Fee item is not found, add the line
If not found then
retVal = oLines.AddLine()
retVal = oLines.SetValue("ItemCode$","/CCFEE")
retVal = oLines.SetValue("ExtensionAmt", ccfee)
retVal = oLines.Write()
If retVal <>0 then
oScript.LinesAdded = 1
End If
End If 'not found

End if 'ccfee

Parents Reply
  • 0 in reply to hyanaga

    Hi !

    Can I assume this is a script attached to SO Invoice Header?  And Pre-Write is definitely where you want to do this, because we'd have to go a different route after the fact.    Has the right methods to look at.  CalculateTotals() probably being the one you need.  And as he said, you shouldn't need to deactivate because you are on the pre-write you are allowing the regular write to occur not doing our own.

    E

Children
No Data