GetRecordIDsFromFoundSet

Returns record IDs from the current found set as a list or a JSON array.

Format 

GetRecordIDsFromFoundSet ( type )

Parameters 

type - a numeric expression that specifies the format of the returned record IDs. See Description.

Data type returned 

text

Originated in version 

22.0

Description 

This function returns the record IDs of all records in the current found set in their current order. Record IDs are unique identifiers that a FileMaker client assigns to each record in a table when the record is created, and they can't be changed.

The type parameter determines the format of the returned data. Use either the constant name or numeric value to specify type.

type parameter Returns record IDs as Examples

ValueNumber (0)

List of values separated by carriage returns

Copy
1
5
21
22
23
7

JSONString (1)

JSON array of values as strings

Copy
["1","5","21","22","23","7"]

JSONNumber (2)

JSON array of values as numbers
Copy
[1,5,21,22,23,7]

ValueNumberRanges (3)

List of values with ranges1

Copy
1
5
21-23
7

JSONStringRanges (4)

JSON array as strings with ranges1

Copy
["1","5","21-23","7"]
  1. For ValueNumberRanges and JSONStringRanges, consecutive record IDs are compressed into ranges to help reduce the size of the returned data.

Notes 

  • The returned record IDs can be used with the Go to List of Records script step to recreate the same found set when specifying a layout based on the same table.

  • If no records are found, this function returns an empty result in the specified format. For an empty list of values, it returns an empty string (""). For a empty JSON array, it returns "[]".

Example 1 - Get record IDs as a list of values

Returns record IDs as a carriage return-separated list.

Copy
GetRecordIDsFromFoundSet ( ValueNumber )

If the current found set contains records with IDs 101, 102, and 105, this example returns:

Copy
101
102
105

Example 2 - Save found set to recreate later

Saves to a global field a JSON object containing the record IDs of the current found set and the current layout name.

Copy
Set Variable [ $recordIDs ; Value: GetRecordIDsFromFoundSet ( JSONStringRanges ) ]
Set Variable [ $currentLayout ; Value: Get ( LayoutName ) ]

Set Variable [ $foundSetInfo ; Value: 
  JSONSetElement ( "{}" ; 
    [ "recordIDs" ; $recordIDs ; JSONArray ] ; 
    [ "layout" ; $currentLayout ; JSONString ] 
  )
]

Set Field [ Global::LastFind ; $foundSetInfo ]

For a found set on the Contacts layout, the JSON object saved in Global::LastFind could look like this:

Copy
{
  "recordIDs": ["1-3", "5", "7-9"],
  "layout": "Contacts"
}

Later, another script can go to the same layout and found set using the Go to List of Records script step script step.

Copy
Set Variable [ $foundSetInfo ; Value: Global::LastFind ]
Set Variable [ $recordIDs ; Value: JSONGetElement ( $foundSetInfo ; "recordIDs" ) ]
Set Variable [ $layoutName ; Value: JSONGetElement ( $foundSetInfo ; "layout" ) ]

Go to List of Records [ List of record IDs: $recordIDs ; Using layout: $layoutName ; Animation: None ]