Type.RecordFields
TypeReturns a record describing the fields of a record type, where each field value is a record with Type and Optional sub-fields.
Syntax
Type.RecordFields(type as type) as recordParameters
| Name | Type | Required | Description |
|---|---|---|---|
type | type | Yes | A record type whose field descriptors are returned. |
Return Value
record — A record where each field name maps to a descriptor record with Type and Optional properties.
Remarks
Type.RecordFields returns a record describing the field declarations of a record type. For each declared field in the type, the result contains a field with the same name whose value is a descriptor record with two properties:
- Type — the M type value for that field (e.g., type text, type nullable number)
- Optional — true if the field may be absent, false if it is required
Type.RecordFields is the inverse of Type.ForRecord. Together they allow round-tripping between a record type and its programmatic descriptor representation. Use Type.RecordFields to:
- Inspect which fields a record type declares and what their types are - Extract field type information from a connector-provided schema - Build generic functions that adapt behavior based on a record's declared structure
Note that this function operates on a type value — not a record value. To get the type of an existing record, use Value.Type(record) first, then pass the result to Type.RecordFields. Also note that Type.RecordFields only returns declared fields; for open record types with extra undeclared fields, those extra fields are not visible in the output.
Examples
Example 1: Inspect fields of a typed record type
let
RT = Type.ForRecord(
[
Name = [Type = type text, Optional = false],
Age = [Type = type number, Optional = true]
],
false
)
in
Record.ToTable(Type.RecordFields(RT))Example 2: Access the type of a specific declared field
let
RT = Type.ForRecord([Name = [Type = type text, Optional = false]], false),
Fields = Type.RecordFields(RT)
in
Fields[Name][Type]The final output — retrieves the field descriptors from the record type using Type.RecordFields, then reads the Type property of the Name field to confirm it is type text.
Result | |
|---|---|
| 1 | type text |
Example 3: Check whether the Age field is declared optional
let
RT = Type.ForRecord(
[
Name = [Type = type text, Optional = false],
Age = [Type = type number, Optional = true]
],
false
),
Fields = Type.RecordFields(RT)
in
Fields[Age][Optional]The final output — retrieves the field descriptors from the record type using Type.RecordFields, then reads the Optional flag of the Age field to confirm it is true.
Result | |
|---|---|
| 1 | TRUE |