Autoincrementing values

I’m experimenting with creating a “Microsoft like” autoincrement (key)field in a table. What I have cooked up is this in the OnInsert trigger of, let’s say table “MyTable” where I have a keyfield (type:integer) called “KeyField”: //Variable: rec2 as record, MyTable IF rec2.FIND(’+’) THEN Rec.KeyField := Rec2.KeyField + 1 ELSE Rec.KeyField := 1; This works of course fine on key fields, but I wonder if there is a better way to do this. What if the field I’m incrementing is not a key field, so the value I get from the last record isn’t necessarily the highest. I’d really like to use the domain aggregate function “DMax” here. Does this approach meet the requirements of a multiuser environment? Should I lock the table in some point? I’d like this to be bullet-proof so that the users don’t end up trying to insert the same value… Comments? /Pauli Edited by - paurola on 2001 Aug 15 15:14:59

Two comments: 1) Generally for numeric primary key fields your method is the right one. However you must do a “locktable” in a multiuser environment. 2) For other keys the official and foolprooved method is to use Navisions Number series. ------- With best regards from Switzerland Marcus Fabian

I agree with Marcus in regards to non-primary key numbers. The number series works great. Also, depending on what you are trying to do, you can use autosplit key to create new numbers. Bill Benefiel Manager of Information Systems Overhead Door Company (317) 842-7444 ext 117

As Marcus says LockTable If you KeyField is not the primary key for the table,one other thing you must do is SETCURRENTKEY. //Variable: rec2 as record, MyTable Rec2.SETCURRENTKEY(KeyField); IF rec2.FIND(’+’) THEN Rec.KeyField := Rec2.KeyField + 1 ELSE Rec.KeyField := 1; David Cox MindSource (UK) Limited Navision Solutions Partner Email: Web: