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 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 a comment in the Manage Database dialog. If any field comment in the table starts with [LLM], then only those comments that start with [LLM] are shown. The [LLM] prefix is removed from the description value.

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 Comment

CreationDate

[LLM] Creation date for product

Price

[LLM] Price of the product in USD

ProductID

[LLM] Primary key that uniquely identifies a product

ProductName

[LLM] Descriptive name of the product

Status

Status of product in inventory. Values are In Stock, On Order

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 that because at least one field comment starts with the [LLM] tag, only the fields with the [LLM] tag include a description. The g_UserFavorites field is omitted entirely because it's a global field, which isn'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