Page 1 of 1

How to automatically assign account codes to customers?

Posted: Fri Aug 04, 2006 3:51 pm
by Andrew
My company's customers are generally COD accounts or credit card accounts, and are members of a wine club. I'd like the system to automatically assign a numeric account code to each new customer we create automatically. If our customer is an account customer, I would still like to let our users enter an alphabetical account code. Is this possible? If so, any clues on how to go about it?

Posted: Fri Aug 04, 2006 3:57 pm
by COBS Tech Support
Place this script inside the Customer Screen Script section of the Screen Builder. If the account code is left blank, a numeric account code will be assigned to the account automatically. This will be based on the next available numeric customer account.

If operators enter an account code, this will be used instead.

* Mode = 3 'save record' event
If Mode = 3
* SCRMode() = 1 = add a new record
If SCRMode() == 1 .And. IsEmpty(SCRRead("CUSCODE"))
Declare nRecNo Type Number
Declare nNextNo Type Number
nRecNo := Custrec->(RECNO())

* Find closest match to customer account 99999999
Custrec->(Find("99999999",, TRUE))
Custrec->(Skip(-1))
nNextNo := VAL(Custrec->Cuscode) + 1
Custrec->(Goto(nRecNo))
SCRWrite("CUSCODE", NTrim(nNextNo))
Endif
Endif