Is this possible?


#1

I have been trying increment a field by 1 each time addrecord is invoked. It is the composition/output of the field that I am not able to “figure out.”

I want the field (Invoice Number) to contain the year and to display like this 2017001, 2017002, etc. So come January next year the invoices would appear 2018001, etc.

Is this doable?

Daniel


#2

Yes. You will need to write a procedure named “.NewRecord” . The name is case sensitive and it begins with a dot. It will run every time you add a record. You would keep the current invoice number in a permanent variable, increment that, and then assign it to your Invoice Number field.

Permanent CurrentInvoice
Define CurrentInvoice, val(datepattern(today(),"yyyy"))*1000
if val(datepattern(today(),"yyyy"))*1000 > CurrentInvoice
    CurrentInvoice = val(datepattern(today(),"yyyy"))*1000
endif
CurrentInvoice = CurrentInvoice+1
AddRecord
«Invoice Number» = CurrentInvoice
Save

#3

Thank you Dave. It works like a charm.

You are one of the reasons this forum is outstanding.

Daniel