GetFieldsOnLayout

Returns a list of the fields on a layout as JSON data.

Format 

GetFieldsOnLayout ( layoutName )

Parameters 

layoutName - a text expression representing the name of the layout. If layoutName is an empty string (""), the current layout is used.

Data type returned 

text

Originated in version 

22.0

Description 

This function returns a JSON object containing information about fields on the specified layout that are accessible to a find.

Fields that meet any of the following criteria are excluded:

The returned JSON object has the following structure:

Copy
{
    "layout_name": "LayoutName",
    "fields": {
        "TableOccurrence::FieldName1": {
            "type": "string",
            "description": "Field annotation or comment (optional)"
        },
        "TableOccurrence::FieldName2": {
            "type": "number"
        }
    }
}
  • The layout_name key contains the name of the layout.

  • The fields object contains key-value pairs for each accessible field.

  • Each field's key is its fully qualified name (for example, TableOccurrence::FieldName).

  • Each field's value is an object with a type key (number if the field's data type is number; otherwise, string).

  • An optional description key is included if the field has an annotation (see Defining advanced field options) or a comment (see Defining and changing fields) defined in the Manage Database dialog. If a field has both, the annotation is used as the value of the description key. If a field has only a comment, then the comment is used. If either starts with [LLM], the [LLM] prefix is removed for backward compatibility with the [LLM] tag convention used in versions earlier than FileMaker 26.0.1.

Notes 

Example 1 

Returns a JSON object describing the fields accessible to a find on the Products layout.

Copy
JSONFormatElements ( GetFieldsOnLayout ( "Products" ) )

If the Products layout has these fields:

Field name Annotation Comment

CreationDate

Creation date for product

 

Price

Price of the product in USD

 

ProductID

Primary key that uniquely identifies a product

Product ID

ProductName

 

[LLM] Descriptive name of the product

Status

 

 

g_UserFavorites

Global field containing the current user's favorite products

 

The function returns:

Copy
{
    "fields"
    {
        "Products::CreationDate"
        {
            "description" : "Creation date for product",
            "type" : "string"
        },
        "Products::Price"
        {
            "description" : "Price of the product in USD",
            "type" : "number"
        },
        "Products::ProductID"
        {
            "description" : "Primary key that uniquely identifies a product",
            "type" : "number"
        },
        "Products::ProductName"
        {
            "description" : "Descriptive name of the product",
            "type" : "string"
        },
        "Products::Status"
        {
            "type" : "string"
        }
    },
    "layout_name" : "Products"
}

Notice the following:

  • ProductID: The description key contains the annotation (the comment is ignored).

  • ProductName: The description key contains the comment with the [LLM] prefix removed (no annotation exists).

  • Status: No description key appears (no annotation or comment exists).

  • g_UserFavorites: The field is omitted entirely (global fields aren't accessible to a find).

Example 2 

Returns a list of all fields on the current layout and a list of all fields on the current layout that are accessible by a find. This may point out fields that you weren't aware were not accessible to a find.

Copy
Let (
[
    layoutFields = FieldNames ( Get ( FileName ) ; Get ( LayoutName ) ) ;
    findFields = JSONListKeys ( GetFieldsOnLayout ( Get ( LayoutName ) ) ; "fields" ) ;

    sortedLayoutFields = SortValues ( layoutFields ; 1 ) ;
    sortedFindFields = SortValues ( findFields ; 1 ) ;

    $$result = "All fields on the current layout:" & ¶ & sortedLayoutFields & ¶ & 
    "Of these, the fields accessible to a find are:" & ¶ & sortedFindFields
] ;
$$result
)

Possible output stored in $$result for the Products layout:

Copy
All fields on the current layout:
CreationDate
Photo
Price
ProductID
ProductName
Status

Of these, the fields accessible to a find are:
Products::CreationDate
Products::Price
Products::ProductID
Products::ProductName
Products::Status