Page 1 of 1

Script to clear reference field on invoices

Posted: Thu Dec 08, 2005 8:30 am
by Susan Jones
I need a script that will go through a particular customer account and clear the reference (order number) field on those transactions. I could this manually but it would take forever. Does anyone have a script that already does this sort of thing?

Thanks

Posted: Thu Dec 08, 2005 8:56 am
by COBS Tech Support
Try this script. It can also be adjusted for other purposes by changing the 'Reference' field to alter other information on transactions. But do not use it to change amount fields as this will corrupt the transaction.

* Erase Reference field entry on customer invoices
* Dangerous!!

Declare cAccount Type Character
Declare lNoLock Type Logical
Declare nCount Type Number
lNoLock := FALSE
nCount := 0

* Prompt for account code and accept 8 upper
* case characters only

FormCreate()
* 8 spaces in each character string because codes are 8 long
FormAdd("Account Code", " ", "!!!!!!!!")

If .Not. FormShow("Account Code To Erase", "Erase", "Cancel")
Goto End
Endif

cAccount := FormResult(1)

If IsEmpty(cAccount)
Echo("Account code was blank. Cannot continue.")
Goto End
Endif

* Open invoice table if not already open
OpenTable("Invoice")

* 2nd index is sorted by account code
If .Not. Invoice->(Find(cAccount, 2))
Echo("No Match Found")
Goto Cleanup
Endif

* Create & show a progress window
EchoBoxOn("Clearing Reference For " + cAccount, "Scanning Invoice File...")

:Loop
If .Not. cAccount = Invoice->Acccode
Goto Cleanup
Endif

If .Not. IsEmpty(Invoice->Reference)
If Invoice->(LockRecord())
Invoice->Reference := ""
nCount := nCount + 1
EchoBox(, "Cleared: " + NTrim(nCount))
Else
lNoLock := TRUE
Endif
Endif

Invoice->(Skip())
Goto Loop

:Cleanup

EchoBoxOff()

If lNoLock
Echo("One or more invoice transactions could not be locked!")
Endif

* Clear any locks that may be left open
Invoice->(UnlockRecord())
* Close invoice table if it was opened here
CloseTable()

:End

If nCount > 0
Echo("Total transactions with cleared tax field: " + NTrim(nCount))
Endif