{"title":"DataTransfer.AddConstantValue(Any, Integer) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/datatransfer/datatransfer-addconstantvalue-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-addconstantvalue-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-addconstantvalue-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":"Specifies the given value is to be set in the given field in the destination table.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"DataTransfer.AddConstantValue(Any, Integer) Method","slug":"datatransferaddconstantvalueany-integer-method","at":0,"chars":1704},{"level":2,"title":"Syntax","slug":"syntax","at":198,"chars":90},{"level":2,"title":"Parameters","slug":"parameters","at":288,"chars":266},{"level":2,"title":"Remarks","slug":"remarks","at":554,"chars":322},{"level":2,"title":"Example","slug":"example","at":876,"chars":684},{"level":2,"title":"Related information","slug":"related-information","at":1560,"chars":144}],"text":"# DataTransfer.AddConstantValue(Any, Integer) Method\n> Version: _Available or changed with runtime version 10.0._\nSpecifies the given value is to be set in the given field in the destination table.\n## Syntax\n```al\n DataTransfer.AddConstantValue(Value: Any, DestinationField: Integer)\n```\n## Parameters\nDataTransfer\nType: datatransfer-data-type\nAn instance of the datatransfer-data-type data type.\nValue\nType: ../any/any-data-type\nThe value to set in the destination field.\nDestinationField\nType: ../integer/integer-data-type\nThe destination table field.\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 set a constant value for a field when copying data in rows or fields of table to another table. See Transferring Data Bewteen Tables<../../devenv-data-transfer>.\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\nGetting Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}