Brian Dunning's FileMaker Custom Functions

FieldRepetitionLast ( field ; maxRepetition )

Returns the highest non-empty repetition for a repeating field.

  Average rating: 4.0 (2 votes) Log in to vote

Jonathan Mickelson   Jonathan Mickelson - Show more from this author

Share on Facebook Share on Twitter

  Sample input:
FieldRepetitionLast ( TheaterSeats_Row1_r20 ; "" )
  Sample output:
18

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

----------------------------------------------------------------
FieldRepetitionLast ( field ; maxRepetition )
----------------------------------------------------------------

-- DESCRIPTION --

Returns the highest non-empty repetition, to match the behavior of "Last ( Table::RepeatingField )" which returns the highest non-empty repetition's value.
NOTE: This calculation uses Recursion, but only as many as the parameter 'MaxRepetition'.

-- EXAMPLES --

FieldRepetitionLast ( TheaterSeats_Row1_r20 ; 20 ) = 18 when the 18th repetition has "John" entered in it.

Use this function with a script to automate putting a value into the highest available empty repetition:
Set Field [ TheaterSeats_Row1_r20 [ FieldRepetitionLast ( TheaterSeats_Row1_r20 ; "" ) +1 ] ; "Jane" ]

Use this funtion with a script to loop though clearing all repetitions of a repeating field:
Loop
Exit Loop If [ FieldRepetitionLast ( TheaterSeats_Row1_r20 ; "" ) = 0 ]
Set Field [ TheaterSeats_Row1_r20 [ FieldRepetitionLast ( TheaterSeats_Row1_r20 ; "" ) +1 ] ; "" ]
End Loop

-- PARAMS --

field - any repeating field, or expression that returns a reference to a repeating field.
maxRepeat - (Optional) A number representing the highest repetition to begin counting down to test for the Last entered value.
If left blank, it will count down from 100.

-- RESULT --

number - a number representing the highest non-empty repetition's value

 

Comments

Dave_E   Dave_E
Feb 19, 2019
I can't get it to cooperate when I pass it a variable for the field parameter.
 

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: