Normal Topic Need some guidance on generating sequential number (Read 1146 times)
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Need some guidance on generating sequential number
Mar 22nd, 2008 at 8:45pm
Print Post Print Post  
I've got a client database working, and I need to have a field called 'ClientNo' that needs to get a sequential number put into it.

The behavior I want is this:

User opens the "CLIENTS" form in Add mode, and so 'On-Form-Entry' I want to put a global value 'gvClientNo' into the 'ClientNo' field on the form.

Then, when the user finally saves the record 'On-Form-Exit' I want the programming to use XLOOKUPR to determine the highest value for 'ClientNo' in the database, to be sure that another user hasn't already saved a record with the same value. If there's a problem I would bump up the ClientNo by one, and then save and update the globalvalue.

The problem I'm running into is the @XLOOPUPR() function. Everytime I use it, I only get zero back. I'm using the programming from the one-sheet on numbering, which can be found here: http://www.lantica.com/Support/sesame_onesheet_11.html
Code
Select All
// Only assign the number if
// this is a new record which
// has been changed.

var vNextNum as Int

If(@IsNew)
{
	If(@Modified)
	{
		vNextNum = @ToNumber(@XLookupR(@FN, "9999999", "Key", "Key")) + 1
		If Not @Error
		{
			Key = vNextNum
		}
	}
} 



So my programming looks like this:

Code
Select All
var vNextNum as Int
vNextNum = @ToNumber(@XLookupR(@FN, "9999999", "ClientNo", "ClientNo"))
		If Not @Error
		{
			ClientNo = vNextNum
				Write("The new ClientNo is: " + vNextNum)
		}
 



But when I run it, all I get is '0' as the value of vNextNum.

What am I doing wrong with XLookupR?
  
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Need some guidance on generating sequential nu
Reply #1 - Mar 22nd, 2008 at 10:14pm
Print Post Print Post  
If ClientNum and Key are Number fields, then try to use 9999999 without quotes and see if it works. I am also kind of newbie. If that does not work, I am sure someone will guide you. I am using this in my application and it works fine.  Do you have any other  form in the application? If, so you will have to mention the name of the form.  Also use WriteLn Slate to debug the problem, I am sure that will clarify the problem at hand.
  
Back to top
 
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Need some guidance on generating sequential nu
Reply #2 - Mar 22nd, 2008 at 11:13pm
Print Post Print Post  
The ClientNo field is a Number field, yes. I tried it without quotes, and it still doesn't work. I do have other forms in the application, so I tried declaring the external key and the source as "CLIENTS!ClientNo" both with and without quotes, and for some reason it won't work.
  
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Need some guidance on generating sequential nu
Reply #3 - Mar 23rd, 2008 at 1:00am
Print Post Print Post  
If you have no Client Numbers assigned yet, then 0 will be the result because it looks like you are forgetting to add 1 to the highest number.
vNextNum = @ToNumber(@XLookupR(@FN, "9999999", "ClientNo", "ClientNo")) + 1

2.  Do you have a LookUp password in Security?


Just curious, since you may be changing the number anyway when the record is closed, why not just assign the number on closing so you don't have to check it again?  If you need it when opening because some logic is based on it, or other things happen based on that number, won't they become invalid if you find someone has already made a permanent number?
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Need some guidance on generating sequential nu
Reply #4 - Mar 23rd, 2008 at 1:05am
Print Post Print Post  
Quote:
I tried declaring the external key and the source as "CLIENTS!ClientNo" both with and without quotes

This is a copy of real working code (except for the form name for clarity). You do not want to use the form name in the source parameter - just the LE name.
Code
Select All
RecordNo = @TN(@XLookupR(@Fn, 999999, "MyFormName!RecordNo", "RecordNo")) + 1 



Also, if the applicaton is secured, you need to provide an "X User" name and password.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Need some guidance on generating sequential nu
Reply #5 - Mar 23rd, 2008 at 7:39am
Print Post Print Post  
Since the Lookup is the internal lookup, what I mean, it is from the same application, security should not be the problem. Why don't you use simple @xlookup( ) from the same layout and see if it works. If it does then Security is not the issue. If it does not work then probably security is the issue.
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Need some guidance on generating sequential nu
Reply #6 - Mar 23rd, 2008 at 12:58pm
Print Post Print Post  
Bharat_Naik wrote on Mar 23rd, 2008 at 7:39am:
it is from the same application, security should not be the problem.

That is not correct. An XLookup to the same application will still fail if there is no "X User" info, and the app is secured.


(I didn't mean that to appear like a scolding, I just wanted it to be clear.  Smiley)
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Need some guidance on generating sequential nu
Reply #7 - Mar 23rd, 2008 at 2:28pm
Print Post Print Post  
Thanks Carl.  It is good to know x-User and Password is required of internal lookups even for administrator when security is set.
« Last Edit: Mar 23rd, 2008 at 3:48pm by Bharat_Naik »  
Back to top
 
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Need some guidance on generating sequential nu
Reply #8 - Mar 23rd, 2008 at 3:46pm
Print Post Print Post  
Thank you, everyone, for the input. When I go into Security Settings and put my Admin settings (username/password) in as the 'X User' then it starts to work. I'm trying to use both methods because I figure it's even more secure. I would prefer to use a globalvalue, because then I could adjust the numbers if needed, but figured using both methods might be worth trying.

I see your point Bob, I'll have to take another look at it.
  
Back to top
IP Logged