GetRecordIDsFromFoundSet
Returns record IDs from the current found set as a list or a JSON array. To get IDs for related records, specify the name of a table occurrence or portal.
Format
GetRecordIDsFromFoundSet ( type { ; tableOccurrenceOrPortal } )
Parameters
type - a numeric expression that specifies the format of the returned record IDs. See Description.
tableOccurrenceOrPortal - a text expression that specifies the name of a related table occurrence or the object name of a portal on the current layout.
Parameters in braces { } are optional.
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, or the record IDs of all records related to the current record by the specified table occurrence or portal. 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 |
|---|---|---|
|
|
List of values separated by carriage returns |
Copy
|
|
|
JSON array of values as strings |
Copy
|
|
|
JSON array of values as numbers |
Copy
|
|
|
List of values with ranges1 |
Copy
|
|
|
JSON array as strings with ranges1 |
Copy
|
-
For
ValueNumberRangesandJSONStringRanges, consecutive record IDs are compressed into ranges to help reduce the size of the returned data.
To get the IDs of related records in a table occurrence, use the tableOccurrenceOrPortal parameter to specify the name of a related table occurrence. The related record IDs are returned in the sort order specified by the relationship. See Creating and changing relationships.
To get the IDs of related records in a portal on the current layout, use the tableOccurrenceOrPortal parameter to specify the object name of the portal (see Naming objects). The returned record IDs are filtered and sorted according to the portal's settings in the Portal Setup dialog. See Creating portals to display related records.
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 "[]".
-
If the
tableOccurrenceOrPortalparameter is specified, this function first tries to match its value to a table occurrence name. If that fails, it tries to match the value to the object name of a portal. If no match is found, this function returns "?".
Example 1 - Get record IDs as a list of values
Returns record IDs as a carriage return-separated list.
GetRecordIDsFromFoundSet ( ValueNumber )
If the current found set contains records with IDs 101, 102, and 105, this example returns:
101
102
105
Example 2 - Get related record IDs from a portal as a JSON array of numbers
Returns related record IDs as a JSON array of numbers from the portal object named ContactsPortal.
GetRecordIDsFromFoundSet ( JSONNumber ; "ContactsPortal" )
If the portal in the current record has three related records that the portal sorts and filters to have the IDs 1101, 702, and 1015, this example returns:
[1101,702,1015]
Example 3 - 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.
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:
{
"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.
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 ]