Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages

Shopping Cart
Shopping Cart


Free Newsletter


Privacy Policy

FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.


 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

GetNthRecordSet ( fieldName ; recordNumStart ; recordNumEnd )

Rate this function:  

  Average rating: 3.9  (66 votes)
  Discuss this Custom Function

Jonathan Mickelson, Thought Deveopment Corp.

Calculates a return delimited and sorted, values list from related, or local, field data.

Sample Input:
GetNthRecordSet ( Children::Name ; 1 ; "" ) == where 3 children's names exist, unsorted.

GetNthRecordSet ( FirstName ; 2 ; 4 ) == where 5 records in found set sorted by FirstName
Sample Output:


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.


--------------- CUSTOM FUNCTION DESCRIPTION BELOW ---------------------

Syntax: GetNthRecordSet ( fieldName ; recordNumStart ; recordNumEnd )


Description: Creates a return delimited value list of the values from the field specified,
beginning with the recordNumStart and ending with recordNumEnd. The
resultant value list' scope and sort are determined by the source field;
thus for local fields the sort is determined by the current sort of
records in the found set, for related fields it is by the relationship sort.

fieldName - Any local field, related field, or an expression that returns a field.
NOTE: For repeating fields this Custom function will only
see the first repetition, per record. Also, Globals will behave
similarly and the global will be display once for each record.

recordNumStart - The record number from which you want to begin getting data.
A null ("") or 0 value will set the start at the first record.

recordNumEnd - The record number after which you want to stop getting data.
A null ("") or 0 value will evaluate until the the last record based upon
the current field context, if the fieldname is local, it uses the FoundSet,
if the field is from a differnt context (ie. related field) it attaempts to use the
count of a related field that has a value, currently set to #, which is an
unstored calc of record number in every table (you can change this).
This parameter is inclusive, thus 10 will end the value list with the
10th record, including the contents of the field in that record, followed by
a return character.

Output Format: A return delimited text value list of the the contents of fieldName dictated
by the provided start and end record numbers, each value will be followed
by a return character.

Note: The result of GetNthRecordSet() will not be updated when the record
referred to by GetNthRecordSet() is a record other than the one in
which the calculation is currently being evaluated, ie. you may need to
refresh the value for related fields.

Examples: Given the following related Field data for Children::FirstNames, from record 1
of a table of parents:
Related Record 1 = Jimmy
Related Record 2 = Suzzie
Related Record 3 = Johnny
Related Record 4 = Dweezle

GetNthRecordSet ( Children::FirstNames ; "" ; "" ) = Jimmy¶Suzzie¶Johnny¶Dweezle¶

GetNthRecordSet ( Children::FirstNames ; 1 ; 3 ) = Jimmy¶Suzzie¶Johnny¶

GetNthRecordSet ( ParentFirstName ; "" ; "" ) = Value list of all parent names
in current found set, in sort order,
ending with the last record in the
current found set.

GetNthRecordSet ( ParentFirstName ; 30 ; "" ) = Value list beginning with the
30th parent name till the last
record in current found set,
in sort order.

Special Thanks: To Ray Cologon, for refining the IsValid test instead of a cumbersome
case test and his ubiquitously simplified code ideas!

To Erik Shagdar, for revising the function to improve it's speed and lighten
the memory impact in variable declarations, and for re-posting the improved version
for everyone to benefit from!

1.3 - 2018-07-02 ( Jonathan Mickelson ) Fixed two bugs:

(1) There was a bug in empty "recordNumEnd" declarations (though you could just require them) when calculating from a related record. It always used Get(FoundCount) for the endNumber even when evaluating a related child record. If user had a found set of 1 record locally, but was getting a related set of 3 records, it would only return the first related value.

Since the original calculation calls for empty 'recordNumEnd' parameters, the calc was improved to detect that the fieldName is from a different context than the current layout, and will attempt to get a count of the related values, via counting a known related field, in this case a field named # that is an unstored calc of Record Number, that exists in all tables of my solutions. (You could change this, or make it another field that you have, like a "__pkID" )

(2) There was a bug that due to FileMaker's way of counting Values, if the trailing return was left off, following a blank last value, FM wouldn't count the last blank value with Value Count.
Thus: "1¶2¶¶¶" where the 1st and 2nd related records had values and the 3rd and 4th didn't, would result in an erroneous Value Count = 3, rather than 4.
This was corrected by structuring the calc so that every value that gets returned will be followed by a return.

1.2 - 2018-06-14 ( Jonathan Mickelson ) Removed one additional call to GetNthRecord, storing and testing the result.
Restored some Case functions so the "else" can be omitted without defining "".
1.1 - 2017-12-05 ( Erik Shagdar ): 2x speed improvement - loop over the records ONCE instead of testing for validity,
then getting the value. added formatting. added documentation. converted case into if functions.
declare end var inside of the let to simply test below. use existing params instead of declaring
new variables.
1.0 - 2006-03-02 ( Jonathan Mickelson ) original version.

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

This is my Custom Function and I want to edit it


5 most recent comments | Show all 11 comments

work not by paste in fm11
(need operator)

Bonino, CH Bern
July 05, 2014 3:45am

Hi Bonino,

I just opened a new file, copied from the website and pasted it in successfully. The message you saw was most likely one due to the three parameters needing to be named, and/or the name of the function needing to be the same (as it's a recursively self-referencing function).

I'd also suggest re-checking that the copy grabbed all the text, sometimes a partial copy can mess up the calculation by missing a parenthesis.

I hope it works out for you!

Jonathan, Los Angeles
July 05, 2014 5:18pm

Be really nice if this could evolve so that it could return from text fields any chosen string!!!

jLT StructuresFromSilence, Kendv,IN USA
March 27, 2015 3:47pm

made the function twice as fast - the original tests for validity, then recursively calls itself, getting the value:

// GetNthRecordSet ( fieldName ; recordNumStart ; recordNumEnd )
// version 1.1, Jonathan Mickelson, Thought Deveopment Corp,

Get return-delimited list of values for the specified field from the found set.

Uses the same sort order as the records.


1.1 - 2017-12-05 ( eshagdar ): 2x speed improvement - loop over the records ONCE instead of testing for validity, then getting the value. added formatting. added documentation. converted case into if functions. declare end var inside of the let to simply test below. use existing params instead of declaring new variables.
1.0 - 20xx-xx-xx ( xxxxx ): brought in.
0.0 - 20xx-xx-xx ( jmickelson ): posted on

Let ( [
recordNumStart = If ( recordNumStart < 1 ;
1 ;
) ;
recordNumEnd = If ( IsEmpty ( recordNumEnd ) or recordNumEnd = 0;
Get ( FoundCount );
thisVal = If ( IsValid ( GetNthRecord ( fieldName ; recordNumStart ) ) ; /* this limits "?" result on empty related records */
GetNthRecord ( fieldName ; recordNumStart );
) ;
nextStart = recordNumStart + 1
] ;

thisVal &
If ( nextStart ≤ recordNumEnd;
"¶" & GetNthRecordSet ( fieldName ; nextStart ; recordNumEnd ) ;

Erik Shagdar, New York
December 05, 2017 10:21am

Thanks Erik for posting your updated version!

I've made a few additional modifications to speed it up further and simplify the number of operations used in the function.

Due to the changes, a small tradeoff for speed was made: A valid value of the text character "?" as the result on a value line will be made blank, as if it wasn't the correct value, or was an empty result. For instance if you had three records and the field held the following text values in them: "3", "?", "James" respectively in the text field, the result would be:



Rather than:


This allowed one less GetNthRecordCall, which is a speed improvement that was worth this small tradeoff.

Jonathan Mickelson, Los Angeles
June 14, 2018 10:32am

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 1 + 7 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. ChiSquare3x2 ( param ; param ; param ; param )
  (Tue, Aug 14, 6:33am)
2. ReverseByteOrder ( bytes )
  (Thu, Aug 09, 12:06pm)
3. BytesToDec ( hex )
  (Thu, Aug 09, 11:47am)
4. GetAsHexBytes ( number ; bytes )
  (Thu, Aug 09, 10:50am)
5. ValCorrelationCoeff ( XValueList; YValueList; Xmean; Ymean; XStdDev; YStdDev )
  (Wed, Aug 08, 4:17pm)
6. ValLeastSquaresSlope ( XValueList; YValueList; Xmean; Ymean )
  (Wed, Aug 08, 4:10pm)
7. ValueMath ( List1 ; List2 ; operation )
  (Wed, Aug 08, 4:05pm)
8. GetExtension ( File )
  (Tue, Aug 07, 10:22am)

RSS Feed of Custom Functions