Normal Topic Preventing duplicate Invoice numbers (Read 398 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Preventing duplicate Invoice numbers
Sep 5th, 2007 at 4:20pm
Print Post Print Post  
When a user clicks the "Assign Invoice Number" button, the database does a lookup into itself, finds the highest Invoice number that has been saved, and adds 1 to it.  I use the same technique to assign Workorder and Customer numbers.  Here's some code:
Code
Select All
// Only assign Code if this is a new record which has been changed.

var vNextNum as Int

If(@IsNew)
{
	If(@Modified)
	{
		vNextNum = @ToNumber(@XLookupR(@FN, "99999999", "INVOICE!INVOICE_NO_1", "INVOICE_NO_1")) + 1
		If Not @Error
		{
			INVOICE_NO_1= vNextNum
			INVOICE_DATE = @Date
		}
	}
} 




Today two of my users created Invoices with the same invoice number.  Sigh.

Any hints on how I can prevent this?
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Preventing duplicate Invoice numbers
Reply #1 - Sep 5th, 2007 at 4:26pm
Print Post Print Post  
Hello Scott,

After assigning the Invoice Number, save the record. Or use a Global Value instead of @XLookupR().

Here is what is happening
Client 1 clicks button
Invoice number 456 is the highest saved invoice, so vNextNum is 457
Invoice_No_1 is assigned the value of 457
Client 1 continues to add data to that record

Client 2 clicks button
Invoice number 456 is the highest saved invoice(as Client 1's record has not yet been saved), so vNextNum is 457
Invoice_No_1 is assigned the value of 457

Client 1 and Client 2 both save. Two different records with one invoice number.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Bug - duplicate Invoice numbers
Reply #2 - Sep 5th, 2007 at 4:49pm
Print Post Print Post  
Thanks Ray, I figured it was something like that.  My grasp of Global Values is slippery, so I'll throw a FormCommit("") in there after assigning the code.
  

**
Captain Infinity
Back to top
IP Logged