Brian Dunning's FileMaker Custom Functions

GetRecordNumber ( _field ; _value )

Given a field value, returns its current Record Number within the current Found Set

  Average rating: 3.8 (19 votes) Log in to vote

Gary   Gary - Show more from this author
GC Consulting
http://GCConsulting.cc

Share on Facebook Share on Twitter

  Sample input:
GetRecordNumber ( author::name ; "Douglas Adams" )
  Sample output:
42

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

Returns the first line number that contains _value, of a list of _field values of all records in the current found set
Returns NULL ("") when _value is not in the list
Returns the correct line number , no matter whether the found set is sorted or not !
=> which is IDEAL for Go To Record/Request/… script step

If it doesn't work, you probably not calling it with a field reference, but with a field value:
_field is a field reference, not a value:
If the field name is stored inside a field, use Evaluate ( ) => GetRecordNumber ( Evaluate ( g::tmpT ) ; g::tmpN )

Based on the ListValues ( Field ) recursive function from Koji Takeuchi:
Given the list of Koji Takeuchi, added number strings at the beginning of each line, followed by a tab character and the line value
At the end, searches for a tab, the _value and reads its line number, then returns the line number

Sample:
GetRecordNumber ( author::name ; "Douglas Adams" )
=> Returns the number 42 (if the record with "Douglas Adams" is the 42nd record in the current found set).

 

Comments

unix   unix, Japan
Mar 29, 2016
Undefined Null is used in this function.
I tried replacing it with "", but not get result.
 
Gary   Gary, GC Consulting
Mar 29, 2016
Hi,

sorry about the «Null» function, you're right. I already changed it to "", which is the exact same thing, as you have done. I use the Null function because it makes for much better reading and understanding of code afterwards.

If it still doesn't work, you are probably not calling the function with a field reference, but with a field value (whereas the _value is a value):
_field is a field reference (not a value):
If the field name, for example «author::name» is stored inside of a field, use Evaluate ( ) => GetRecordNumber ( Evaluate ( g::tmpT ) ; g::tmpN )

This will probably do it.

Thanks for your question. Now, it should be clearer.

Gary
 
Milton Wayne Trickey   Milton Wayne Trickey, Nil
Mar 18, 2021
Hi Gary,
I tried using your custom function and kept on getting error messages.
I have set up a script as follows:
Set Variable ($$PlayersName) value (Players::_id_fk_Player Nickname).
Go to Related Records Show only related records from table "Players" using layout "Players Prize Money List" in a new window.
Show All Records
Perform Find [Restore] Players Results::Total Played:[>.1]
Sort Records [Restore; with dialog Off] Table Players, Sort Order _id_fk_Player Nickname Ascending.
Set Field (Players::PlayerToFind;$$PlayersName)
All of this works fine, the Layout is in List mode.
What I need to add is your custom function from here to find the RecordNumber that matches the contents of the field - Players::PlayerToFind and puts the RecordNumber into the field named Players::PlayerToFindLineNumber.

This is to enable me to rank a player based on different search criteria:
e.g. Games Played, Prize Received, First Placings etc. whereby a player may have Played 100 games and is ranked 1st in the list when a find is carried out using that criteria, but when you change the find criteria to First Placings, he may have only come 1st once so he would be further down the list. I hope this makes sense.
Thankyou in advance

Milton
 
Gary   Gary, GC Consulting
Mar 18, 2021
Hi,

if all the names are stored in Players::_id_fk_Player,
and if the name that you are searching for is in $$PlayersName,
and if you are in a layout that contains the field Players::_id_fk_Player,
the following function call will return the record number of the first occurance of $$PlayersName in Players::_id_fk_Player of all records in the current found set.
Using a script line like this, you will have the record number stored in $RecNum:

Set Variable [ $RecNum ; Value: GetRecordNumber ( Players::_id_fk_Player ; $$PlayersName ) ]

Now, you can use $RecNum to go to the record in question using the script step:
Go to Record/Request/Page [ With Dialog: Off ; $RecNum ]

That’s exactly what the CF is for.

Hope that helps,

Gary
 

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: