# RecordRef.FieldIndex(Integer) Method
> Version: _Available or changed with runtime version 1.0._
Gets the FieldRef of the field that has the specified index in the table that is referred to by the RecordRef.
## Syntax
```al
Field :=   RecordRef.FieldIndex(Index: Integer)
```
## Parameters
RecordRef
Type: recordref-data-type
An instance of the recordref-data-type data type.
Index
Type: ../integer/integer-data-type
The index of the field.
## Return Value
Field
Type: ../fieldref/fieldref-data-type
The FieldRef of the field that has the specified index.
## Remarks
The fields in the primary key are always listed first in the index. Therefore, the order of the fields in the index is not necessarily the same as the order of the fields in the table.
If the index is out of the range supplied or if no table is selected, then the method returns an error.
## Example
```al
var
    SalesInvHdr: RecordRef;
    FldRef: FieldRef;
    Str: Text[1024];
    Text001: Label 'Index 1: %1\\';
    Text002: Label 'Index 2: %2\\';
    Text003: Label 'Index 3: %3';
begin
    SalesInvHdr.Open(112);
    FldRef1 := SalesInvHdr.FieldIndex(1);
    FldRef2 := SalesInvHdr.FieldIndex(2);
    FldRef3 := SalesInvHdr.FieldIndex(3);
    Message(Text001 + Text002 + Text003, FldRef1.Caption, FldRef2.Caption, FldRef3.Caption);
end;
```
The message window displays the following:
 Index 1: No.
 Index 2: Sell-to Customer No.
 Index 3: Bill-to Customer No.
  The following illustration shows the first fields in table 112, Sales Invoice Header, and shows the keys for table 112. The order of the fields in the index differs from the order of the fields in the table. The index lists the field in the primary key first.
## Related information
recordref-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/recordref/recordref-fieldindex-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/recordref/recordref-fieldindex-method/
