DataTransfer.AddFieldValue(Integer, Integer) Method

Version: Available or changed with runtime version 10.0.

Specifies a source and destination field, where the values from the source field are to be copied to the destination field. The data types of the fields must match, except CODE to TEXT which is allowed.

Syntax

 DataTransfer.AddFieldValue(SourceField: Integer, DestinationField: Integer)

Parameters

DataTransfer
 Type: DataTransfer
An instance of the DataTransfer data type.

SourceField
 Type: Integer
The source table field.

DestinationField
 Type: Integer
The destination table field.

Remarks

The DataTransfer object can only be used in upgrade code and it will throw an runtime error if used outside of upgrade codeunits.

Use this method when copying data in rows or fields of table to rows or fields of another table. For more information, see Transferring Data Bewteen Tables.

Note

Copying the SystemID and data audit fields using CopyRows is supported in Business Central version 21.5 and later.

Example

In 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.

local procedure CopyRows()
var
    dt: DataTransfer;
    src: Record Source;
    dest : Record Destination;
begin
    dt.SetTables(Database::Source, Database::Destination);
    dt.AddFieldValue(src.FieldNo("PK"), dest.FieldNo("PK"));
    dt.AddFieldValue(src.FieldNo("S3"), dest.FieldNo("D3"));
    dt.AddConstantValue('X', dest.FieldNo(D2));
    dt.AddSourceFilter(src.FieldNo("S2"), '=%1', 'A');
    dt.CopyRows();
end;

See Also

DataTransfer Data Type
Getting Started with AL
Developing Extensions