Wednesday, January 16, 2008

Microsoft Dynamics AX 2009 - some of the new development features

Alexei Eremenko from Microsoft Russia has posted a number of articles about the new features that will be available in DAX 2009.
The original link, which is in Russian (but the main thing to look at is the code, which is universal): http://blogs.msdn.com/aeremenk/archive/2008/01/15/7118429.aspx

I would like to make a brief review of the features he talked about for the English-speaking population and another feature I liked that Alexei did not mention.

Let's start with the support for union in SQL statements (but only when using Query* classes).


query = new Query();
query.queryType(QueryType::Union); // The other value of QueryType is "Join"



Another Exception type has been introduced, which now actually allows to catch the DuplicateKey exception:

Table t;

try
{
while select forupdate t
{
test.Field1 = ‘xyz’;
t.update();
}
}
catch ( Exception::DuplicateKeyException, t )
{
infolog(‘Record already exists - ‘ + t.Field1 );
}



The bulk DML statements now allow using inner/outer joins, and you can access the result of the update_recordset operation to get the number of rows that were updated:

update_recordset batchJob setting
Status = BatchStatus::Canceled,
EndDateTime = thisDate,
Finishing = 1
where batchJob.Status == BatchStatus::Cancelling
notexists join batch
where (
(batch.Status == BatchStatus::Ready ||
batch.Status == BatchStatus::Executing ||
batch.Status == BatchStatus::Hold ||
batch.Status == BatchStatus::Cancelling)
&& batch.BatchJobId == batchJob.RecId
);

rowsUpdated = (batchJob.RowCount() > 0); // get the number of updated rows with rowCount()



And, the feature I enjoyed, is that we now have crossCompany support in X++. Meaning you can access data from tables from a number of companies in one query.
Here are code snippets to explain what I mean:

static void DataBaseAccess_CrossCompany(Args _args)
{
InventTable inventTable;
container companyContainer = ['IN1', 'QMS'];
;
while select crossCompany : companyContainer inventTable
where inventTable.ItemId == "B-R14"
{
print inventTable.ItemId, " -- ", inventTable.dataAreaId;
}
pause;
}



This code will print ItemId from 2 companies, even though InventTable has the property SaveDataPerCompany set to Yes.

The same functionality is available with the Query classes:

static void DataBaseAccess_CrossCompany_Query(Args _args)
{
Query query = new Query();
QueryBuildDataSource qbds = query.addDataSource(tableNum(InventTable));
QueryRun queryRun;
InventTable inventTable;
;
qbds.addRange(fieldNum(InventTable, ItemId)).value(queryValue("B-R14"));

query.allowCrossCompany(true);
query.addCompanyRange("IN1");
query.addCompanyRange("QMS");

queryRun = new QueryRun(query);
while (queryRun.next())
{
inventTable = queryRun.get(tableNum(InventTable));
print inventTable.ItemId, " -- ", inventTable.dataAreaId;
}
pause;
}



If you don't add any specific company ranges, the data will be retrieved from all companies you have access to.

Microsoft Dynamics AX 2009 has a lot more to offer, of course. But enough for today.

10 comments:

Anonymous said...

Hi!
I'm new to AX and I have searching the web for some usefull tips and tricks on development. Your blog will come in handy. If you have time for a quick question; been browsing the Query class but cant find any good method for parsing ANSI SQL, is there any such way of sending an SQL statment to the server and catch the result in a temptable or simular. much like you do with the SqlCommand class in C#.
Best Regards Thomas Sundberg

Vanya Kashperuk said...

Well, you cannot really convert X++ sql commands to Query classes.
But if you just want to use the sql to display data, let's say, in a form, than you can override the executeQuery method on the form datasource and paste the code there instead of the call to super.

But that'a really ugly way of doing things

Anonymous said...

hi
this is amazing !
but do you know ant thing about the upgrade methodology ?
thanks

Vanya Kashperuk said...

There will be a document available to partners and customers, describing in detail the upgrade process.

Also, we are working on tools and scripts to make this process as easy as possible

Anonymous said...

hello there, i have question how can you show 2 reports at same time by only one click... is it possible? right now i can show report per menu item i need to show 2 reports at same time by relation of salesid. pls help

Vanya Kashperuk said...

Yes. Showing 2 reports at once is possible.
Just override the clicked method on the MenuItemButton that opens the first report, and call another menu item before (or after) the call to super().

Your clicked method would look something line the following:

MenuFunction mf = new MenuFunction(menuItemOutputStr(InventDimPosted), MenuItemType::Output);
Args args = new Args();
;
//specify all needed arguments for the args here
mf.run(args);

super();

Anonymous said...

Hi there,

thanks for the idea of showing 2 reports at one time. but i still confused, how can i call the other menuitem for the 2nd report, in your sample you call in function menuItemOutputStr(InventDimPosted) report how i can add to show the other menuitem with the report on it pls. give me more clear sample on this problem...

Vanya Kashperuk said...

Sorry, man, I did not understand what exactly your problem is here.

The first report will be called from the menu Item (on the form) directly. The other will be called from code in the clicked method of this menu item.

If you have more questions, pls. feel free to contact me directly on my e-mail

Anonymous said...

May i know your direct email address? tnx

Vanya Kashperuk said...

ivan(dot)kashperuk(at)gmail(dot)com

Replace (dot) with .
Replace (at) with @