wguan

Help with Set Next Serial Value and Max (Field) + 1 after import

Discussion created by wguan on Jan 24, 2014
Latest reply on Jan 24, 2014 by wguan

Hi I've been learning FileMaker for the past few months and are currently working with 2 versions of a database. I have a Deployed database and a Development database.

 

The Development database is based off of the deployed version. I have been making changes to the Development version's layouts. The layout and field names in the Development version match all field names in the Deployed version, so I'm here trying to write a script that will import all data over from Deployed into Development.

 

Preparation and thoughts:

1. Delete all records on all tables in Development version.

2. When I import records from Deployed into Development, the next auto-enter serial number for any given Development table may be a lower number than the next auto-enter serial number for the corresponding table from the Deployed database. Therefore I have created a script step to "Set Next Serial Value ( Table::PrimaryKeyField; Max (Table::PrimaryKeyField ) + 1"

3. The auto-enter serial number is a number. Field type is a number. Examples: 1, 2, 3, 5, 10, 15, 200, 315.

 

Sample script step to import a table:

Go to Layout ["Example Layout" ( Example )]

Import Records [ No Dialog; "DeployedDatabase.fmp12"; Add; Windows ANSI]

Show All Records

Set Next Serial Value [ Example::PrimaryKeyField; Max ( Example::PrimaryKeyfield ) + 1 ]

Show Custom Dialog ["Import Complete"; "Import has completed"]

 

Issue:

My Example table has 400 records with some missing in between. The latest record had the highest primary key serial number of 600; the lowest serial number for a record is 74. The correct, next auto-enter serial number for a new record should be 601. The problem I'm experiencing is, the next auto-enter serial number is set to be 75 after the import. I assume the Max function would get 600+1, but instead I got 74+1.

 

Is there a step I'm missing or something that I'm doing wrong in my script? I'd appreciate any help. Thank you!

Outcomes