AR Invoice Header PreWrite script not working correctly during Repetitive Invoice Selection

SOLVED

Sage 100 Advanced 2018. I have a script designed to fire on AR Invoice Header PreWrite: If a BillTo account is specified in Invoice Header it should confirm the checkbox UDF_BTST is checked in AR_Customer, and if not should displays a message reminding the user to check the box. 

This script triggers and works correctly when entering a single invoice manually. It also fires as desired, but does not work correctly, when the invoice is being generated using Repetitive Invoice Selection: then the message appears for EVERY invoice where a Bill-To Customer number exists in RI Entry, whether or not the UDF_BTST checkbox in AR_Customer is checked.

I believe the problem is that the GetChildHandle call is not working during the Repetitive Invoice Selection process, though it does work during manual invoice entry. Can someone confirm that? I'd like to avoid having to create another business object hundreds of times during the invoice selection process, which is why I want to use GetChildHandle if possible.

Here is a watered down version of the script should anyone care to test:

'Check to see if BTST feature is used
oCust = 0
sINBT = ""              'Invoice Header Bill-To Customer Number, if exists
sARBT = ""            'AR_Customer UDF_BTST

retVal = oBusObj.GetValue("BillToCustomerNo$", sINBT)

'If a Bill-To Customer Number has been entered, confirm UDF_BTST checkbox value

If sINBT <> "" then
   SET oCust = oBusObj.AsObject(oBusObj.GetChildHandle("CustomerNo"))
   retVal = oCust.GetValue("UDF_BTST$", sARBT)

   'if UDF_BTST checkbox isn't checked, display message to user

   If sARBT <> "Y" then
      sMsg = "IMPORTANT: Please open AR Customer Maintenance for " & sDiv & "-" & sCustNo & ", go to the Invoice tab "
      sMsg = sMsg & "and CHECK the -BT Used?- box (on the right) to indicate the BT/ST feature has been used, "
      sMsg = sMsg & "to remind others to look at Invoice History Inquiry when reviewing this account."
      retMsg = oSession.AsObject(oSession.UI).MessageBox("",sMsg,"Style=OK")
   End If
End If

  • +1
    verified answer

    If you have verified the script is firing when intended than perhaps the child object isn't on the correct record as you are expectig it to be.

    Experiment with throwing oBusObj.ReadAdditional "CustomerNo" either before or after the oBusObj.GetChildHandle("CustomerNo") but before the oCust.GetValue.

    Another option might be to set the key values yourself in the oCust object and then use Find to make sure you are on the correct customer record and then use GetValue.

  • 0 in reply to David Speck

    Thank you David! For anyone else running in to a similar problem, you may need to force read of the child object by adding the following line right before the Set oCust line:

    retVal = oBusObj.ReadAdditional("CustomerNo")