Tuesday, July 21, 2009

Iterate all records from grid

To iterate all record from a grid is accomplished by :

VendOutPaymForParams_FI exportSetupLocal;

for (exportSetupLocal = exportSetup_ds.getNext();exportSetupLocal;exportSetupLocal=exportSetup_ds.getNext())
{
B....
}

Tuesday, July 14, 2009

Getting rid of the "Loss of precision" warning message

A question came up at today's webinar where a developer had a (presumably legitimate) reason to cast a real value into an integer value. The X++ language does not allow explicit casting (there's no support for it in the language), but the compiler will do its best to satisfy the user and do the conversion on its own. In this case, however, it issues a warning message, lest this is not what the user wanted.

One solution is to use the anytype type to hold the vaue for conversion and then using the any2int function, as shown below:

static void Job47(Args _args)
{
real r = 3.13;
int i = r; // Warning is issued here
anytype a;

a = r; // Assign to an anytype variable...
i = any2int(a); // ... and back into an int

print r;
print i;
pause;
}
This should be packaged into a function, maybe called int RealToInt(real arg).

Another way would be doing the conversion in managed code (through the System.Convert::ToInt32(object) method), but the performance will not be as good because of the marshalling that needs to take place.

Forthcoming changes to the X++ language

Very informative link for new X++ release
http://blogs.msdn.com/x/archive/2009/06/29/forthcoming-changes-to-the-x-language.aspx

Monday, July 6, 2009

How to get all changes done in usr layer into project.

Create a new project and open the project.

Press Ctrl+f3 or click on the icon advance filter/sort on the toolbar of the
project, a dialog with name project filter will be opened.

In project filter, select append and aot.Click select for the query dialog
to open enter the query layer usr in the utillevel range and click Ok to
close query dialog .
Click Ok to close the project filter dialog. This will create a project with the objects of usr layer.

Friday, July 3, 2009

Physics behind the data source refresh(), reread() and research() method

.refresh() will not reread the record from the database. It basically
just refreshes the screen with whatever is stored in the form cache.

.reread() will only re-read the CURRENT record from the DB so you
should not use it to refresh the form data if you have added/removed
records. It's often used if you change some values in the current
record in some code, and commit them to the database using .update()
on the table, instead of through the form datasource. In this case
.reread() will make those changes appear on the form.

.research() is probably what you want. This will rerun the existing
form query against the datasource, therefore updating the list with
new/removed records as well as updating existing ones. This will
honour any existing filters and sorting on the form.

.executeQuery() is another useful one. It should be used if you have
modified the query in your code and need to refresh the form. It's
like .research() except it takes query changes into account.

In general, you only need to use one of these in any specific
circumstance.

Set the specific row in a grid

The specific row of grid can be set by calling the dataSource_ds.findRecord(Common _buffer) method. Suppose we want to select third row (i.e Account # 4003) in a customer table grid, here is the code

CustTable_ds.findRecord(CustTable::find('4003'));