Seriale Annuale
Inviato: domenica 26 febbraio 2006, 23:16
Ciao a tutti !
Questa funzione personalizzata, utilizzabile anche come calcolo, ma solo dagli utilizzatori di FM8 ( o FM8 Advanced), risolve il problema di avere un numero seriale che ricomincia da 1 all'inizio di un nuovo anno.
Inseritela in un campo testo con opzione di Auto-Inserimento in base a calcolo, togliete la spunta a "non valutare se i campi di riferimento sono vuoti" e togliete la spunta anche a "non sostituire il valore, se presente".
Questa funzione personalizzata, utilizzabile anche come calcolo, ma solo dagli utilizzatori di FM8 ( o FM8 Advanced), risolve il problema di avere un numero seriale che ricomincia da 1 all'inizio di un nuovo anno.
Codice: Seleziona tutto
/*
AnnuallySerial custom function
Author: Daniele Raybaudi
Format: AnnuallySerial ( AEfield ; digit )
Result: text
parameters:
AEfield: text - the text field wich will hold the serial number; it must be setted as auto-enter, always evaluate
digit: number - the number of digit (#) that must increment by one and restart from one every new year
This custom function can be used for:
1) Autoenter a serial number that increments annually
2) the format of the serial number is essentially: YYYY##
3) the serial number may have how many digits (#) you choosed
The Auto-Enter field must be setted to always evaluate;
the custom function isn't recursive, so you can use it as a simple calc;
the custom function will work only with FMP8 and above.
12/27/2005
*/
Let([
year = Year ( Get ( CurrentDate ) );
lastId =GetNthRecord (AEfield; Get ( TotalRecordCount ) - 1);
lastYear = Left ( lastId; 4 )
];
year
&
Case(
year ≠ lastYear or Right ( lastId ; digit ) = 10^digit -1; Right ( 10^digit ; digit-1 ) & "1";
SerialIncrement ( Right ( lastId ; digit ) ; 1 )
)
)