Copying a record in Dynamics 365

Copying a record in Dynamics 365 can be easily done two different ways using x++. Those are buf2buf and data.
I am going to show you how to use each and what the differences are between the two.

Data: Here is an example of how to copy a record using data.

Copying a record in Dynamics 365 with data

When copying a record with data we can see that the system fields are copied over as well. This includes fields like RecId, and DataAreaId.
Most of the time this is not an issue as the system fields are overridden when the record gets saved.
However there can be some issues when copying records between companies.

Buf2buf: Here is an example of how to copy a record using buf2buf.

Copying a record in Dynamics 365 with buf2Buf

Using buf2Buf does NOT copy over system fields but still copies over all of the data fields from the original record.
This is a safer way to copy records when crossing legal entities in Dynamics 365.
By right clicking on buf2Buf and going to the code we can see how the method ignores the base system fields when copying the record.

buf2Buf source code

Copying a record in Dynamics 365 can be really easy as long as you know when to use which method! Check out more common X++ methods!

Read another developer tips and tricks article for Dynamics 365!

For more tech blogs, subscribe to the code_marks news letter: http://eepurl.com/gZCMQz

Author

3 Comments

  1. Pingback: Color Coding Records in D365 with x++ | Marked Code

Write A Comment