D365F&O - X++ - Buf2Buf() vs Data() method vs assignment opertaor for one table buffer assignment to other

Assigning one table record to another table record, there are three ways this can be done:

1- Assignment operator 

table1 = table2;

In this case, shallow copy of table record is assigned to second table record, which means instead of creating a copy, it points to the same table record.

2- Table.data() method

table2.data(table1);

Generally we use table.data() method for replicating a table record, instead of passing each  field one by one. However, table.data() method also copies the system fields, and if we are inserting data across companies , we cannot use table.data() method.

3- Buf2Buf() method

Buf2Buf(fromTable, toTable);

If we don't want to copy system fields, we can use Buf2Buf() method.

Also, for intercompany insert of data , we should use Buf2Buf() method with changeCompany() method().

Comments

Popular posts from this blog

D365F&O - X++ - Best Practice Warning BP Rule: [BPErrorUnknownLabel]: Path:

D365F&O - X++ - How to Enable/Disable button on form based on a condition in D365F&O using Event handlers.

D365FO - X++ - Generate CAR (Customized Analysis Report) report of custom model