# Record.SetCurrentKey(Any [, Any,...]) Method
> Version: _Available or changed with runtime version 1.0._
Selects a key for a table.
## Syntax
```al
[Ok := ]  Record.SetCurrentKey(Field1: Any [, Field2: Any,...])
```
## Parameters
Record
Type: record-data-type
An instance of the record-data-type data type.
Field1
Type: ../any/any-data-type
*[Optional] Field2*
Type: ../any/any-data-type
## Return Value
*[Optional] Ok*
Type: ../boolean/boolean-data-type
true if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.
## Remarks
You can use SetCurrentKey to hint a sort order to the Business Central server. With the fields suggested in SetCurrentKey, the Business Central server then searches available key definitions and adds an ORDER BY clause with the fields from the key to the SQL statement issued to the database.
A key matches the fields passed to SetCurrentKey if the key fields are either an exact match, or if the fields are a prefix of the key fields.
If no key is found that matches the fields given to SetCurrentKey, the sort order will still be applied but without a key, the query may be slower.
When you use SetCurrentKey, the following rules apply:
 You can't use SetCurrentKey on:
   FlowFilter fields
   Nested FlowFields
   FlowFields on ExternalSQL tables
   Blob fields
   FlowFields on virtual tables
   FlowFields that query across application database / tenant database
   FlowFields that query different table types
  These fields aren't sortable. If any of these fields are used in the method, it returns false at runtime and an error occurs if not handled.
 Only active keys are considered.
 When the system searches for a key, the first occurrence of a key that starts with the specified fields is selected, which means:
   Fields that are part of a IncludedFields definition aren't used when searching for a matching key.
   If you specify only one field as a parameter when you call SetCurrentKey, the key that is selected might consist of more than one field.
   If the field that you specify is the first component of several keys, the key that is selected might not be the key that you expect.
## Related information
record-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/record/record-setcurrentkey-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/record/record-setcurrentkey-method/
