Brian Dunning's FileMaker Custom Functions

LastRepNumber ( repeatingField ; maxRepeat )

Returns the number of the last not empty repetition

  Average rating: 3.9 (44 votes) Log in to vote

Daniele Raybaudi   Daniele Raybaudi
ACI
http://www.aci.it

Share on Facebook Share on Twitter

  Sample input:
LastRepNumber ( repeatingField ; 10 )
  Sample output:
returns a value between 1 and 10 (or "" if repeatingField is empty)

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Returns the number of the last not empty repetition, much like Last(repeatingField) returns its contents.
Can be used with both 7 and 8 version of FileMaker, but is most useful with 8, where fields can be reached specifying the repetition number by a calculation.
For example, to set the next empty repetition to "whatYouWant" you can use:

Set Field [repeatingField [LastRepNumber ( repeatingField ; 10 ) +1];"whatYouWant"]
(where repeatingField has 10 rep).

This function comes in hand also if you want to clear all repetitions.
A simple loop:

Loop
Exit Loop if [LastRepNumber ( repeatingField ; 10 ) = ""]
Set Field [repeatingField [LastRepNumber ( repeatingField ; 10 )];""]
End Loop

 

Comments

Jim   Jim, NY
Mar 20, 2014
Does not work if the repeatingField is referencing another repeatingField that is a calculation.
This recursive function will return an incorrect number (always blank), since during the recursion, the repeatingField has not yet caluclated the result from the other repeatingField.

Only works with repeatingField that are not based on other calculations.
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.