Tech Tip: A utility to synchronize sequence number for a table
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: August 16, 2013
Depending on circumstances it is possible for holes to be left in sequence numbers saved in a table. Below is a utility method that...
- takes a pointer to a field
- determines the table it belongs to
- get the highest sequence number value saved
- get the current sequence number value for the table
- compares the two numbers
- if they are not the same, sets the correct sequence number for the table
This utility can be called during startup or before a call to NEW RECORD since it preserves any current selection.
If (True) If (False) Begin SQL * Name: SequenceNo_SyncOneTable Path: SequenceNo_SyncOneTable $1 - Pointer - Pointer the the field that holds sequence numbers */ End SQL End if C_TEXT($MethodName_T) $MethodName_T:=Current method name //=============== Declare Variables ============================ //method_parameters_declarations C_POINTER($Fld_P;$1) //-------------------------------------------------------------------- //method_wide_constants_declarations //-------------------------------------------------------------------- //local_variable_declarations C_LONGINT($SeqNo_L;$Params_L) End if $Params_L:=Count parameters If ($Params_L>0) $Fld_P:=$1 $Tbl_P:=Table(Table($Fld_P)) // Preserve any existing selection // CUT NAMED SELECTION($Tbl_P->;"SQ_CurrentSel") //======================== Method Actions ================================== ALL RECORDS($Tbl_P->) ORDER BY($Tbl_P->;$Fld_P->;<) REDUCE SELECTION($Tbl_P->;1) $SeqNo_L:=Get database parameter($Tbl_P->;Table Sequence Number) If ($SeqNo_L#$Fld_P->) SET DATABASE PARAMETER($Tbl_P->;Table Sequence Number;$Fld_P->) End if //======================== Clean up and Exit ================================= // Restore any prior selection // USE NAMED SELECTION("SQ_CurrentSel") End if |
Below is a code snippet showing how to call the utility
SequenceNo_SyncOneTable(->[Invoices]InvoiceNo) |