solfm_getLastID ( )

Function stats

Average user rating
299
323
9999
Support
FileMaker 10.0 +
Date posted
21 March 2012
Version
1
Recursive function
No

Author Info
 Diego D'Alessio (solfilemaker)

5 functions

Average Rating None

author_avatar



 

Function overview

Prototype

solfm_getLastID  ( valueList )


Parameters

valueList  


Description

Tags:  value list   id   autoincrement  

I wrote this function because I needed to get the next serial number without using FM's own Serial Number.
In order to use this function:
1 - create a value list using as source the field that contains the ID.
2- set a variable (e.g. $newID) and pass the name of the value list.

Demo example here: http://www.filemakerhoy.com/downloads/serial.fp7

Examples

Sample input

valueList


Sample output

12344

 

Function code

Let([

lista=ValueListItems(Get(FileName);valueList);

lineas=PatternCount(lista;"¶");

ultimoSerie=GetValue(lista;lineas)

];
ultimoSerie+1
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/323

    Prototype: solfm_getLastID( valueList )
    Function Author: Diego D'Alessio (solfilemaker) (http://www.fmfunctions.com/mid/299)
    Last updated: 21 March 2012
    Version: 1

*/
// ===================================

 

Comments

Fabrice
22 March 2012



it seems to me that this is going to return a duplicate of the last value because PatternCount ( lista ; ¶ ) will give you the number of values -1.
Valuecount () does this for you.
And... using SerialIncrement instead of +1 would allow.
You could do:
Let (
lista = ValueListItems(Get(FileName) ; valueList ) ;
Case ( lista ; SerialIncrement ( Substitute ( RightValues ( lista ; 1 ) ; ¶ ; "" ) ; 1 ))
)
 Bug report

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (27)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Interface  (15)
Layout  (15)
Text  (14)
Variables  (13)
Filter  (12)
Layout Objects  (11)
Design  (10)
Array  (8)