SetError not displaying correctly and displaying error about credit cards only when processing credit memo via SO_InvoiceHeader

I have BOI Script in the table pre-write events for SO_SalesOrderHeader and SO_InvoiceHeader that do regular expression searches in the ship to address fields for PO boxes when certain ship via types are used, as most of our ship to addresses should not contain a PO Box entry and cause sales tax problems after the fact. My script works in SalesOrderHeader very well, and works in InvoiceHeader except when doing a credit memo.

If I am processing a credit memo through SO Invoice Header I get a different error other than the SetError message I've said to display. Instead I get "You cannot use a credit card payment credit memo is not applied to an invoice." However, I am doing nothing with the credit card tab or trying to apply the invoice. Does anyone have any ideas as to why I'm receiving a different message when doing a credit memo or how to suppress it and display my SetError message? I've put my script below. We are on version 5.10.3 Sage 100 Advanced ERP 2014.

'Language : VBScript

strShipVia = "" : strMsg = "" : strSTA1 = "" : strSTA2 = "" : strSTA3 = ""

If oSession.CompanyCode = "TFP" Then

Set myRegExp = New RegExp

myRegExp.IgnoreCase = True

myRegExp.Global = True

myRegExp.Pattern = "((P(\.?))\s?(O(\.?))\s?)|(Box)"


retVal = oBusObj.GetValue("ShipVia$", strShipVia)


If strShipVia <> "UPS" and strShipVia <> "UPS BLUE" and _

strShipVia <> "UPS ORANGE" and strShipVia <> "UPS RED" and _

strShipVia <> "USPS" and strShipVia <> "FEDEX" Then


retVal = oBusObj.GetValue("ShipToAddress1$", strSTA1)

retVaL = oBusObj.GetValue("ShipToAddress2$", strSTA2)

retVal = oBusObj.GetValue("ShipToAddress3$", strSTA3)


If myRegExp.Test(strSTA1) or _

myRegExp.Test(strSTA2) or _

myRegExp.Test(strSTA3) Then


strMsg = "Error - PO Box cannot be in ShipTo Address."

retFail = oScript.SetError(strMsg)

End If

End If

End If

  • 0
    Bump... anyone with some ideas?
  • 0 in reply to EArter
    Sometimes when i've checked the value in LastErrorMsg and LastErrorNum after doing a SetValue or Write, i have seen some off the wall errors that didn't seem to be related to what i was doing but they also didn't impact what i was doing. You may be able to do an IF condition where if the invoice type is a credit memo and the apply to invoice number is blank and the LastErrorNum is equal to the value returned when you get the error "You cannot use a credit card payment credit memo is not applied to an invoice.", you might be able to set those properties to "" (oBusObj.LastErrorNum = "" : oBusObj.LastErrorMsg = "") and then call SetError and see if you get what you want.