Code highlighting

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.

26 comments:

  1. 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

    ReplyDelete
  2. 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

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

    ReplyDelete
  4. 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

    ReplyDelete
  5. 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

    ReplyDelete
  6. 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();

    ReplyDelete
  7. 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...

    ReplyDelete
  8. 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

    ReplyDelete
  9. May i know your direct email address? tnx

    ReplyDelete
  10. ivan(dot)kashperuk(at)gmail(dot)com

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

    ReplyDelete
  11. HI,
    I need some little help about printing a report that have a control. let's say print only once and lock printing if user need another copy of report must unlock before can print again. How to do this function? Please help if you have any idea. Thank you

    ReplyDelete
  12. Hi again,
    By the way which form can i edit which has the print icon on title bar that shows when you try to print a report. Is it possible to disable this icon print so that if user select Screen, they cannot have control to print the report.
    Is this possible?

    ReplyDelete
  13. hello
    working on a project in mdax 2009, i want to add some forms on top of a form with icons, like u see in the places pane sometimes when u open a form in 2009, say like what i suppose is the user interface

    ReplyDelete
  14. Just copy over one of the list pages that are already present in the application and build on top of it.
    Basically, the way the form looks is controled via the properties on the Design.
    The buttons are called ActionPaneButtons.

    ReplyDelete
  15. Hi Vanya,
    I'm new to AX. I'm trying to make some manual process automated. I'm going to create a class that mimics the form logic. But instead of rewriting all the logics in the form methods, can I call them from a class without bring up the form? For example, if the form is XYZ, how to call XYZ.calcAll method without running the form XYZ? Thanks in advance for your help?

    ReplyDelete
  16. Well, you can definitely call a form method, assuming you have the formRun object.
    If you do, you can simply assign this object to another variable of type Object.
    This way you will avoid the compile-time validation of methoe existance.

    You should check that the method actually exists before doing that. (using SysFormRun::hasMethod)
    Do a search on SysFormRun::hasMethod in AOT - this will show you some examples.

    But, of course, not all code can be executed like that. At least, that's what I think.
    Let me know, if all methods work with no problems.

    ReplyDelete
  17. Thank you Vanya. I'll give it a try and let you know.

    ReplyDelete
  18. Hi Vanya,

    In AX 2009. I'm trying to schedule a report via batch server to email the output, but it stuck in "Executing". When I run the report manually with email option, it pops up a "Allow, Deny" window that I have to click Allow button to get the email sent. I have 2 questions here:

    1. When a report is run in Batch server, the RunOn property needs to be Client or Server?

    2. What are the setup requirements for batch to send email? Does it require some code modification?

    Thanks in advance for your help!

    ReplyDelete
  19. Try setting the RunOn = Client.
    Maybe then the old batch framework will be used, allowing to run the report on the client tier. but even then, i am not sure it would run under the same user as you.
    so not sure how to help you here.
    can you log a request for Microsoft on this?

    ReplyDelete
  20. is it possible to remove the link on the report go to form link.

    ReplyDelete
  21. Actually, I don't think this is possible to do on the report design.
    It is done automatically based on the EDT/Relation setup of the corresponding field

    ReplyDelete
  22. Hi, Can you tell me if we can have the reports with data from different data area id's
    for financial reporting we need the transactions form different companies in same report. Is it possible

    Harry

    ReplyDelete
  23. You should specify this printJobSettings.allPages(true) to allows also run in Server

    ReplyDelete
  24. Hi, Harry, yes, this is possible to use data from different companies to display it in one report.
    Please take a look at the existing reports in AOT, and I am sure there is more than one there that do this.
    I won't write about this, since Reports are obsolete, really.

    ReplyDelete
  25. Hi Vanya,
    Am working on benchmark toolkit to stress test the customized objects on Ax 2009. Am new to Benchmark toolkit. What i found on toolkit was I'll be able to generate Dynamics Ax wrappers only for Tables, Classes and BaseEnums. But wen i want to stress test forms, I am not able to do it.

    So i would want to know if there is a possibility where I can create classes which call the forms and their methods, so that I can generate wrappers for those classes and stress test the forms.

    Please let me know if I can run the forms and call their methods through class methods..

    my mail id: pacchaiprakash(at)gmail(dot)com

    Regards
    Prakash Srinivasan

    ReplyDelete
  26. It's not exactly possible to work with forms from BC.NET.

    ReplyDelete

Please don't forget to leave your contact details if you expect a reply from me. Thank you