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 - Show more from this author
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.
 
Bob, WA   Bob, WA
Jul 5, 2019
Using the Loop example to clear all repetitions does not work if it's a number field and any repetition has zero as the value. It doesn't clear the zero and doesn't exit the loop. Am I doing something wrong?
 
Bob, WA   Bob, WA
Jul 9, 2019
OK, I figured this out. If the last non empty repetition in a number field is 0 (zero) or an invalid entry, the result is maxReapeat instead of the repetition number with the data. The following fixes it and also works if there’s an invalid entry in a date field. It also fixes the loop example to clear all repetitions.

Case (
IsEmpty ( Last ( repeatingField ) ) ; "" ;
GetAsText ( Last ( repeatingField ) ) = GetRepetition ( repeatingField ; maxRepeat ) ; maxRepeat ;
LastRepNumber ( repeatingField ; maxRepeat - 1)
)
 
Bob, WA   Bob, WA
Jul 9, 2019
OK, I figured this out. If the last non empty repetition in a number field is 0 (zero) or an invalid entry, the result is maxReapeat instead of the repetition number with the data. The following fixes it and also works if there’s an invalid entry in a date field. It also fixes the loop example to clear all repetitions.

Case (
IsEmpty ( Last ( repeatingField ) ) ; "" ;
GetAsText ( Last ( repeatingField ) ) = GetRepetition ( repeatingField ; maxRepeat ) ; maxRepeat ;
LastRepNumber ( repeatingField ; maxRepeat - 1)
)
 

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.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: