Paul,
> On Sep 1, 2021, at 6:32 PM, Paul Chernoff via 4D_Tech <[email protected]>
> wrote:
>
> 4D 17.5
>
> Somehow when I create a new record for a table it wants to assign an
> existing record’s primary key to a new record’s primary key field.
>
> How do I get the database to know that this value is already in use for
> this unique field and to start incrementing primary key values starting at
> a higher value?
This code will fix the key for any integer or longint key. Just pass a pointer
to the key field.
// FixAutoincrement 1/28/21
//
C_POINTER($1) // 1/28/16
C_LONGINT($MaxValue) // 1/29/16
//
$FieldPtr:=$1 // 1/28/16
$TablePtr:=Table(Table($FieldPtr)) // 1/9/21
//
GET FIELD PROPERTIES($FieldPtr;$FieldType) // 10/19/18
//
If (($FieldType=8) | ($FieldType=9)) // Integer or Longint 10/19/18
//
$OldMaxValue:=Get database parameter($TablePtr->;Table sequence number)
// 1/4/21
//
$TablePtr:=Table(Table($FieldPtr)) // 1/28/16
//
ALL RECORDS($TablePtr->) // 4/19/16
ORDER BY($TablePtr->;$FieldPtr->;<) // Get highest value 4/19/16
//
$MaxValue:=$FieldPtr-> // 4/19/16
//
If ($MaxValue>$OldMaxValue) // 1/22/21
SET DATABASE PARAMETER($TablePtr->;Table sequence
number;$MaxValue) // 12/19/16
End if // 1/4/21
//
End if // Integer or Longint? 10/19/18
Randy Kaempen
Intellex Corporation
**********************************************************************
4D Internet Users Group (4D iNUG)
New Forum: https://discuss.4D.com
Archive: http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************