tableA.Field1 := tableB.Field1;
tableA.Field2 := tableB.Field2;
...and so on.
Skip fields which do not match.
Wrap the code in a function so you can reuse it. Even if you don't plan to re-use it still wrap it in a separate function - it will make your code more readable,
There is not much philosophy or science there. It is just a series of assigment statements wrapped in a function, nothing more.
When you call ToRecord.TRANSFERFIELDS(FromRecord) the system copies fields from FromRecord to ToRecord. The idea is to build a function doing the almost the same but skipping unwanted fields. Since the TRANSFERFIELDS is called on a destination record (ToRecord.REANSFERFIELDS...) then to make my custom copy fields function similar I am also defining it on source table.
I am also trying to stick to specific naming convention, and call my function CopyFromSomeRec() so furtehr down the code I can clearly see what it is doing
ToRecord.CopyFromRecordA(RecordA)
If the function is suposed to copy fields from some record A to record B, then on table B (destination table) I would create function CopyFromRecordA, with RecordA as a parameter, and inside this function put a series of assignments.
Just note that both TRANSFERFIELDS and a function assigning field values is not supposed to insert anyting into the database. Both are supposed to do in-memory copy - that's it. If you want to make a copy of record A into record B in the database you need to insert that copy into the DB
Answers
tableA.Field2 := tableB.Field2;
...and so on.
Skip fields which do not match.
Wrap the code in a function so you can reuse it. Even if you don't plan to re-use it still wrap it in a separate function - it will make your code more readable,
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
When you call ToRecord.TRANSFERFIELDS(FromRecord) the system copies fields from FromRecord to ToRecord. The idea is to build a function doing the almost the same but skipping unwanted fields. Since the TRANSFERFIELDS is called on a destination record (ToRecord.REANSFERFIELDS...) then to make my custom copy fields function similar I am also defining it on source table.
I am also trying to stick to specific naming convention, and call my function CopyFromSomeRec() so furtehr down the code I can clearly see what it is doing
ToRecord.CopyFromRecordA(RecordA)
If the function is suposed to copy fields from some record A to record B, then on table B (destination table) I would create function CopyFromRecordA, with RecordA as a parameter, and inside this function put a series of assignments.
Just note that both TRANSFERFIELDS and a function assigning field values is not supposed to insert anyting into the database. Both are supposed to do in-memory copy - that's it. If you want to make a copy of record A into record B in the database you need to insert that copy into the DB
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03