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.

AnthonyBlake
  • 2,334
  • 1
  • 25
  • 39

1 Answers1

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.

ceth
  • 44,198
  • 62
  • 180
  • 289
  • 8
    +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(). – Max Jul 19 '12 at 13:18
  • 2
    ah okay, begs the question why its not called something obvious like .copy() – AnthonyBlake Jul 19 '12 at 14:38