{"title":"RecordRef.Truncate([Boolean]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/recordref/recordref-truncate-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-truncate-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-truncate-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":"Deletes all records in a table that fall within a specified range, in an efficient maner.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"RecordRef.Truncate([Boolean]) Method","slug":"recordreftruncateboolean-method","at":0,"chars":3121},{"level":2,"title":"Syntax","slug":"syntax","at":332,"chars":80},{"level":2,"title":"Parameters","slug":"parameters","at":412,"chars":379},{"level":2,"title":"Return Value","slug":"return-value","at":791,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":1029,"chars":459},{"level":2,"title":"Example","slug":"example","at":1488,"chars":1301},{"level":2,"title":"See Also","slug":"see-also","at":2789,"chars":332}],"text":"# RecordRef.Truncate([Boolean]) Method\n> Version: _Available or changed with runtime version 16.0._\nDeletes all records in a table that fall within a specified range, in an efficient maner. Keep in mind that Truncate allows for less concurrency than DeleteAll, as the entire table will be locked until the transaction is committed.\n## Syntax\n```al\n[Ok := ]  RecordRef.Truncate([ResetAutoIncrement: Boolean])\n```\n## Parameters\nRecordRef\nType: recordref-data-type\nAn instance of the recordref-data-type data type.\n*[Optional] ResetAutoIncrement*\nType: ../boolean/boolean-data-type\nSpecifies if the AutoIncrement column should be reset to start from the initial value, or if it should stay at the current value.\nTables without an AutoIncrement field ignore this parameter. The default is true.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue if the table supports truncate; otherwise, false.\nIf you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nTruncate currently isn't supported in the following cases:\n Temporary tables, system tables, and tables of type other than Normal.\n When running within a try function.\n Tables that have a security filter applied.\n When the current filters contain flow fields, or use a high number of marked records.\n When the OnAfter/OnBefore events are subscribed for the table.\n Tables with media fields.\nIn this case, it's recommended to use DeleteAll instead.\n## Example\nThe following example demonstrates how to truncate all records in a table and capture the optional return value to avoid a runtime error when truncate isn't supported.\n```al\nprocedure ExampleTruncate_RecordRef()\nvar\n    RecRef: RecordRef;\n    Ok: Boolean;\nbegin\n    RecRef.Open(50101);\n    Ok := RecRef.Truncate(true);\n    RecRef.Close();\n    if Ok then\n        Message('RecordRef: Truncate succeeded and AutoIncrement reset.')\n    else\n        Message('RecordRef: Truncate not supported; consider DeleteAll.');\nend;\n```\nThe following example demonstrates how to truncate records matching a filter (in this case the table's \"Location Code\" field). This approach is only recommended when the majority of records match the filter because Truncate is most efficient in such scenarios.\n```al\nprocedure ExampleTruncateFiltered_RecordRef()\nvar\n    RecRef: RecordRef;\n    Ok: Boolean;\nbegin\n    RecRef.Open(50101);\n    // Field number 2 corresponds to Location Code in this table\n    RecRef.Field(2).SetFilter('Red');\n    Ok := RecRef.Truncate(false);\n    RecRef.Close();\n    if Ok then\n        Message('RecordRef: Filtered truncate (Location=Red) succeeded (AutoIncrement preserved).')\n    else\n        Message('RecordRef: Filtered truncate not supported; consider deleting manually.');\nend;\n```\n## See Also\nInsert, Modify, ModifyAll, Delete, DeleteAll, and Truncate methods<../../devenv-insert-modify-modifyall-delete-and-deleteall-methods>\nRecord.Truncate([Boolean]) method<../record/record-truncate-method>\nrecordref-data-type\nGetting started with AL<../../devenv-get-started>\nDeveloping extensions<../../devenv-dev-overview>"}