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()

  • 0 in reply to David Speck

    It is certainly good to know about this method (to enable a button without an open record) but for this one I think I'm going to stick with the original strategy I had, which is to make the user open an invoice in the batch first.

    (The business case is: pre-scanned invoices which ship later... and they want to update the Invoice Date in bulk before posting a batch).

  • 0 in reply to Kevin M

    Are you going to force the oUIObj.BT_Accept method or conditionally check if the record was modified? 

    I would lean towards checking if the record was modified in case the user inadvertently changed something just before clicking you button and you script end ups committing the change. Checking if the record has been modified would also allow you the opportunity for the user to use your button on a brand new record, all you'd have to do it just prompt the user if they want to save or cancel the changes. the MessageBox method will return the full value of the button clicked by the user so if you have a Yes and No button, if the user clicks no, it would return No, likewise for Yes.

  • 0 in reply to David Speck

    I already have a Yes No prompt.

  • 0 in reply to Kevin M

    But do you have a condition checking whether or not the current record has been modified or are you just counting on always using BT_Accept instead of BT_Cancel where possibly needed in the event the user inadvertently made a change to the current record?

  • 0 in reply to David Speck

    I am forcing Accept when they click Yes.

    The business case is: pre-scanned invoices which ship later... and they want to update the Invoice Date in bulk before posting a batch.