# number generating scripts that are record independent

This topic is 8005 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

I'm writing a script to generate sequential numbers when attached to a button. It works fine in an individual record, but when I open a new record it resets itself to 1. Is there a way to keep the current number from record to record while continually adding on to said number?

##### Share on other sites

Sequential numbers (serial numbers) are easily set under Define: Fields/Options, and when used, are assigned automatically on the creation of a new record. This would avoid the need for a script.

Hope this is useful.

Peace

Keith M. Davie

##### Share on other sites

I had used that method at first, but then ran into the obstacle of needing to generate multiple numbers per record, so the serial number option wasn't satisfying that need. Sometimes I need 1 or more numbers for an individual record, then on the next record I need the next consecutive number from the previous record.

##### Share on other sites

quote:

Originally posted by smoothdra:

I had used that method at first, but then ran into the obstacle of needing to generate multiple numbers per record, so the serial number option wasn't satisfying that need. Sometimes I need 1 or more numbers for an individual record, then on the next record I need the next consecutive number from the previous record.

Assuming you have 1 field which stores this number and only 1 number in this field, heres what you can do:

Setup a self-relationship by a constant (i.e. a calculation field = 1) and then sort the relationship in descending order by your number field. Now the highest number is the first record in the relationship and you can use "Number = RelationshipName::Number + 1" to get the next highest number.

If the numbers are stored in more than one field or multiple numbers are stored in the field. Use the "Max(field1, field2, etc)" in a calculated field to get the highest number in that record. Then base the relationship and other calculations on this field.

------------------

=-=-=-=-=-=-=-=-=-=-=-=-=

Kurt Knippel

Senior Filemaker Developer

http://www.inthescene.com

mailto:[email protected]

=-=-=-=-=-=-=-=-=-=-=-=-=

##### Share on other sites

You might want to try using a global field to store the last number used.

1) Insert Calculated result of the global field + 1 (called Paste result in older versions)

2) Copy the new result and paste back to global field.

Good luck.

##### Share on other sites

Go to the following website. http://www.databasepros.com/index.html

Go to the Tips & Tricks Section and search for the files on Serials. There are a couple of excellent downloads there.

##### Share on other sites

This topic is 8005 days old. Please don't post here. Open a new topic instead.

## Create an account

Register a new account