Table = Table vs Table.Data(Table)
Asked Answered
S

1

7

What is the difference between the two statements below?

newTable = orginalTable

or

newTable.data(originalTable)

I suspect there is a performance benefit to the .data() method as it is more commonly used in standard AX.

Schober answered 19/7, 2012 at 9:8 Comment(0)
A
10

Try this:

newTable = originalTable;
info(strfmt('%1 %2', newTable.recId, originalTable.recId);

newTable.data(originalTable);
newTable.insert();
info(strfmt('%1 %2', newTable.recId, originalTable.recId);

You'll see that the first statement just creates another one pointer to existing record. The second one creates new copy of existing record.

Allista answered 19/7, 2012 at 13:1 Comment(2)
+1. I'll add that if you don't want to copy system fields from one record to another but only fields carrying a functional meaning (i.e. fields you can see in the AOT), use buf2buf() instead of data().Presber
ah okay, begs the question why its not called something obvious like .copy()Schober

© 2022 - 2024 — McMap. All rights reserved.