Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Serial Number Script

Featured Replies

I need to be able to generate serial numbers in new records. I am aware of the auto-enter serial number features however for this database I would like to use a script to generate a serial number. Does anyone out there have any script suggestions?

Thanks for your help in advance. I am putting the finishing touches on this database and I wanted to add a little more flexibility to the serail number piece of the database.

Edited by Guest

Can you describe the "flexibility" you need in generating serial numbers? It may be the auto-enter serial number feature can handle your needs. Scripts to create serial numbers can be slow when you get a lot of records and should be avoided.

  • Author

I would like my client to be able to issue a serial number after they have filled out their form. I need the script to be able to count then number for records and issue a serial number accordingly. The auto serial number feature issues a number without looking at the current number of files. Hopefully this helps. If you need for me to provide more details I am willing.

You can count the number of records using a relationship. I would use a self-join relationship with the operator as a cartesian product (x) instead of a equijoin (=). This will allow the relationship to see all the related records from any parent record. In this case, the related records and the parent reccords are the same since it's a self-join. Anyhow, once you have the relationship, this simple calculation will count the number of records:

Count(SELFJOIN::SerialField) + 1

Add one so you get the next serial number.

Again, I don't recommend this since it can be slow once you get a lot of records.

And if a record is deleted, the same number will be assigned twice.

See here for a safer method.

Since I have never used a script to generate serial numbers, I was not aware of the issues, although it seems quite obvious now that you point it out. I read through your example but you are still using the auto-enter serial number to create serial numbers. I don't know what the person who originated this post really needs but maybe they need to do something with the serial number once it has been generated. So, it set to create a solution that wouldn't cause the problem you suggest. I have attached a file that should overcome these issues. Basically, it uses a table to keep track of the serial numbers and the script increments the serial number. This could have record locking issues in a multi-user scenario if two people try to create a new record at the same time but is unlikely since it will happen so quickly. Still, you should check for record locking just to make sure.

SERIALSCRIPT.FP7.zip

you are still using the auto-enter serial number to create serial numbers

Yes, I am - because I don't know any other method that is 100% safe. True, we don't know what OP intends to do with the numbers. But it shouldn't matter how the numbers were generated, as long as they are guaranteed to be unique and consecutive.

In your file, if two users are creating a new record at the same time, the second user will not be able to increment the value in SERIALS::SerialNext, due to the record being locked by the first user. But there will be no problem with the next script step - so both users will end up with the same value. Yes, it is unlikely. But given enough time and enough records, it will eventually happen.

  • Author

Thanks for the help guys. I was able to put together a script that took care of the serial number problems.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.