{"title":"DataTransfer.CopyRows() Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/datatransfer/datatransfer-copyrows-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/datatransfer/datatransfer-copyrows-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/datatransfer/datatransfer-copyrows-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":"Copies the rows from the source table to the destination table with the fields selected with AddFields and the filters applied with AddSourceFilter, in one bulk operation in SQL.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":240,"chars":45},{"level":2,"title":"Parameters","slug":"parameters","at":285,"chars":109},{"level":2,"title":"Remarks","slug":"remarks","at":394,"chars":445},{"level":2,"title":"Example","slug":"example","at":839,"chars":684},{"level":2,"title":"Related information","slug":"related-information","at":1523,"chars":205}],"text":"> Version: _Available or changed with runtime version 10.0._\nCopies the rows from the source table to the destination table with the fields selected with AddFields and the filters applied with AddSourceFilter, in one bulk operation in SQL.\n## Syntax\n```al\n DataTransfer.CopyRows()\n```\n## Parameters\nDataTransfer\nType: datatransfer-data-type\nAn instance of the datatransfer-data-type data type.\n## Remarks\nThe DataTransfer object can only be used in upgrade code and it will throw an runtime error if used outside of upgrade codeunits.\nUse this method to copy data in rows of a table to rows in another table. See Transferring Data Between Tables<../../devenv-data-transfer>.\n> NOTE\n> Copying the SystemID and data audit<../../devenv-table-system-fields#audit> fields using CopyRows is supported in Business Central version 21.5 and later.\n## Example\nIn this code example, you copy the PK and S3 fields in the Source table for all rows where S2 equals A and add them as new rows in the Destination table. You use AddConstantValue method to give the field D2 the value X in the inserted rows.\n```al\nlocal procedure CopyRows()\nvar\n    dt: DataTransfer;\n    src: Record Source;\n    dest : Record Destination;\nbegin\n    dt.SetTables(Database::Source, Database::Destination);\n    dt.AddFieldValue(src.FieldNo(\"PK\"), dest.FieldNo(\"PK\"));\n    dt.AddFieldValue(src.FieldNo(\"S3\"), dest.FieldNo(\"D3\"));\n    dt.AddConstantValue('X', dest.FieldNo(D2));\n    dt.AddSourceFilter(src.FieldNo(\"S2\"), '=%1', 'A');\n    dt.CopyRows();\nend;\n```\n## Related information\ndatatransfer-data-type\nTransferring Data Between Tables<../../devenv-data-transfer>\nGetting Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}