{"title":"RecordRef.Next([Integer]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/recordref/recordref-next-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/recordref/recordref-next-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/recordref/recordref-next-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":"Steps through a specified number of records and retrieves a record.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"RecordRef.Next([Integer]) Method","slug":"recordrefnextinteger-method","at":0,"chars":2795},{"level":2,"title":"Syntax","slug":"syntax","at":163,"chars":66},{"level":2,"title":"Parameters","slug":"parameters","at":229,"chars":603},{"level":2,"title":"Return Value","slug":"return-value","at":832,"chars":139},{"level":2,"title":"Remarks","slug":"remarks","at":971,"chars":439},{"level":2,"title":"Example","slug":"example","at":1410,"chars":1248},{"level":2,"title":"Related information","slug":"related-information","at":2658,"chars":137}],"text":"# RecordRef.Next([Integer]) Method\n> Version: _Available or changed with runtime version 1.0._\nSteps through a specified number of records and retrieves a record.\n## Syntax\n```al\n[Steps := ]  RecordRef.Next([Steps: Integer])\n```\n## Parameters\nRecordRef\nType: recordref-data-type\nAn instance of the recordref-data-type data type.\n*[Optional] Steps*\nType: ../integer/integer-data-type\nDefines the direction of the search and how many records to step include. If this parameter is greater than zero, the method will search the number of records specified in Steps forward in the table. If this parameter is less than zero, the method will search the number of records specified in Steps backward in the table. If this parameter is 0, no records are stepped over. If you do not specify this parameter, the method finds the next record.\n## Return Value\n*[Optional] Steps*\nType: ../integer/integer-data-type\nDefines the direction of the search and how many records to include.\n## Remarks\nThis method locates a record positioned a given number of steps forward or backward from the record specified by RecordRef. Movement through the table is governed by the filters and the current key associated with the records. The fields in the record which will be compared with the current key fields must contain appropriate values before the method is called.\nThis method works the same as the ../record/record-next-method.\n## Example\nThe following example opens the Customer table as a RecordRef object, creates a reference to the first \\(No.\\) field, and stores the reference in the MyFieldRef variable. The SetRange method sets a filter that selects all records from 10000 to 40000 in the No. field. The recordref-find-method searches and selects the first record in the filter and counts the number of records that are found. The number of records is stored in the Count variable. The process is repeated by looping through all the records in the filter until no more records are found. The Next method steps through the records and finds the next record because no value is specified for the Steps parameter. The number of records that are found in the range is stored in the Count variable and displayed in a message box.\n```al\nvar\n    CustomerRecref: RecordRef;\n    MyFieldRef: FieldRef;\n    Count: Integer;\n    Text000: Label '%1 records were retrieved.';\nbegin\n    CustomerRecref.Open(Database::Customer);\n    MyFieldRef := CustomerRecref.Field(1);\n    MyFieldRef.SetRange('10000' , '40000');\n    Count := 0;\n    if CustomerRecref.Find('-') then\n      repeat\n        Count := Count + 1;\n      until CustomerRecref.Next = 0;\n    Message(Text000 , Count);\nend;\n```\n## Related information\nrecordref-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}