{"title":"KeyRef.FieldIndex(Integer) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/keyref/keyref-fieldindex-method/","by":"JOP-AL","license":"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/keyref/keyref-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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/keyref/keyref-fieldindex-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Gets the FieldRef of the field that has this index in the key referred to by the KeyRef variable.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"KeyRef.FieldIndex(Integer) Method","slug":"keyreffieldindexinteger-method","at":0,"chars":1671},{"level":2,"title":"Syntax","slug":"syntax","at":234,"chars":65},{"level":2,"title":"Parameters","slug":"parameters","at":299,"chars":149},{"level":2,"title":"Return Value","slug":"return-value","at":448,"chars":125},{"level":2,"title":"Remarks","slug":"remarks","at":573,"chars":234},{"level":2,"title":"Example","slug":"example","at":807,"chars":730},{"level":2,"title":"Related information","slug":"related-information","at":1537,"chars":134}],"text":"# KeyRef.FieldIndex(Integer) Method\n> Version: _Available or changed with runtime version 1.0._\nGets the FieldRef of the field that has this index in the key referred to by the KeyRef variable. Returns an error if no key is selected.\n## Syntax\n```al\nField :=   KeyRef.FieldIndex(Index: Integer)\n```\n## Parameters\nKeyRef\nType: keyref-data-type\nAn instance of the keyref-data-type data type.\nIndex\nType: ../integer/integer-data-type\nThe input index.\n## Return Value\nField\nType: ../fieldref/fieldref-data-type\nThe FieldRef that refers to the field with this index in the key.\n## Remarks\nThe first field in the index must have index 1, the second index 2, and so on. The last field must have index = FieldCount. If the index is out of the range supplied or if no table is selected, the method returns an error.\n## Example\nThe following example displays the caption of a field in a record. The table with ID 18 \\(the Customer table\\) is open with a reference. The Keyref for the record is retrieved by using the KeyIndex Method \\(RecordRef\\)<../library>. The method retrieves the second key in the record and stores the value in the varKeyRef variable. The varKeyRef variable is then used to return the FieldRef. The varFieldRef variable is used to display the caption of the field.\n```al\nvar\n    RecRef: RecordRef;\n    varKeyRef: KeyRef;\n    varFieldRef: FieldRef;\nbegin\n    RecRef.Open(18);\n    varKeyRef := RecRef.KeyIndex(2);\n    varFieldRef := varKeyRef.FieldIndex(1);\n    Message('The Field name is: %1' ,varFieldRef.Caption);\nend;\n```\n## Related information\nkeyref-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}