Button script to change invoice date for a whole batch... error 84

SOLVED

A customer has asked for an easy way to change the invoice date for an entire batch (without using VI).  What I am trying is a button script run from SO Invoice Entry, opening a new object, grabbing the ModuleDate, scrolling through the batch and setting the invoice date one at a time.  That part works, but at the end of the script I get an error 84 (crashing the UI).

Is what I am attempting feasible?  Can I not open a new instance of SO_Invoice_Bus from within an SO Invoice Entry button script?

oInvoiceEntry = oSession.GetObject("SO_Invoice_Bus")
Set oInvoiceEntry = oSession.AsObject(oInvoiceEntry)
oInvoiceEntry.SetIndex("KBATCH")
oInvoiceEntry.SetBrowseFilter(sBatchNo) 
retVal = oInvoiceEntry.MoveFirst()
do until oInvoiceEntry.EoF 
	sLoopInvoiceNo = ""
	retVal = oInvoiceEntry.GetValue("InvoiceNo$", sLoopInvoiceNo)
	if sLoopInvoiceNo <> sInvoiceNo then ' skip over the currently open invoice.
		retVal = oInvoiceEntry.SetValue("InvoiceDate$", sModuleDate)
		retVal = oInvoiceEntry.Write()
	end if
	retVal = oInvoiceEntry.MoveNext()
loop ' oInvoiceEntry
oInvoiceEntry.SetIndex("KPRIMARY")
Set oInvoiceEntry = nothing

Trying to invoke Accept before the loop doesn't change anything.

retVal = oScript.InvokeButton("BT_Accept") 
retVal = oUIObj.HandleScriptUI() 

I also tried with and without forcing close the current invoice (before the loop), with the same error.  (If I do this, the SetValue on the current invoice works, and all the other invoices in the batch are updated, but it still crashes the screen... which is not something I could enable on a customer system).

retVal = oBusObj.Write()
retVal = oBusObj.Clear()

Parents
  • +1
    verified answer

    Is there a reason you are getting a new object handle instead of using the current oBusObj?

    You are only going through the currently select batch, correct?

    I think i have used the invokebutton approach to do what you want while checking the return value first for success before doing anything else, since this is a button script you could also just call oUIObj.BT_Accept() and check its return value before proceeding with the rest of the script. You could also check the oBusObj.RecordChanged property and if 0, just call oUIObj.BT_Cancel() then proceed to loop.

Reply
  • +1
    verified answer

    Is there a reason you are getting a new object handle instead of using the current oBusObj?

    You are only going through the currently select batch, correct?

    I think i have used the invokebutton approach to do what you want while checking the return value first for success before doing anything else, since this is a button script you could also just call oUIObj.BT_Accept() and check its return value before proceeding with the rest of the script. You could also check the oBusObj.RecordChanged property and if 0, just call oUIObj.BT_Cancel() then proceed to loop.

Children