Monday, December 15, 2008

Confusion on the use of tablebuffers in X++

Confusion on the use of tablebuffers in X++
This document has been migrated from TechNet.Navision.com - There has been some confusion surrounding the use of databuffers in X++. Please refer to the examples below for a clarification on the subject.

The examples are based on two buffers declared as:
zipCode buffer1;
zipCode buffer2;

Assigning by reference:
buffer1 = buffer2;

Buffer1 becomes a reference to buffer 2. Referencing buffer1 will have the exact same effect as referencing buffer2. The following example will print an X on the screen.:
buffer1 = buffer2;
buffer2.city = "X";
print buffer1.city;
pause;

Reinitializing with data:
buffer1 = buffer2.data();

Buffer1 is reinitialized to the initial state of the tablebuffer and all data are transferred from buffer2. The example below will insert a record in the zipCode table despite the fact that we start out by setting tmp on buffer1. Stateinformation as lockSelect, current company and a running select statement will be reset on the tablebuffer.
buffer1.setTmp();
select * from buffer2 where buffer2.zipCode == '4100'
buffer1 = buffer2.data();
buffer1.zipCode = "CopyOf" + buffer1.Zipcode;
buffer1.insert();buffer1.data(buffer2.data());

Transferring data only:
buffer1.data(buffer2.data())

All data are transferred from buffer2 to buffer1. The effect is exactly the same as setting all fields in buffer1 equal to all fields in buffer2. No state information changes on buffer1. To make the above example insert records into a temporary copy of the zipcode table we need to change the code 
buffer1 = buffer2.data()
to 
buffer1.date(buffer2.data())


No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...