Friday, November 30, 2012

Report with Sum at Header using Duplicated Query


Your report needs the summation of some fields at the Header portion but you do not want to hack the report classes to achieve that.
Dynamics Ax subtotal is available only at the footer. If you need it in some other section, you would have to find a way around. We will look at an approach where the report query is duplicated for the necessary calculation at the section header.
The demo subsequently will produce the report illustrated in the following figure. The section footer is the subtotal produced by the standard report. The section header on the other hand shows the output of the approach suggested.
Dynamics Ax Report with Sum at Header

Motivation

There are ways to achieve this. The use of duplicated query is motivated by the following factors.
  • It could be applied to existing report without affecting the overall structure. In other words, no changes will be required on the data source and other sections in the report.
  • The calculation is in accordance to the filters set by the user without additional work.
  • The report query will be handled by Dynamics Ax report subsystem while we will only work on the duplicated copy of the query.

Technique Highlight

Basically we will have two copy of the same query. At the section group header, we will loop the duplicated copy until the next header group is reached. The necessary work is performed while we loop and the value to be shown at the group heading is prepared prior to executing the group header. Then the report subsystem will take over and loop the original copy of the query.
The following code segment illustrates the technique explained above.
// loop as long as within the same subheading group.
do {
  custTransLoop = qrHead.get(custTransLoop.TableId);
  if (custTransLoop.AccountNum == CustTrans.AccountNum) {
    rSum += custTransLoop.AmountCur;
  }
  else {
    break//heading group changed.
  }
while (qrHead.next());

mrSum = rSum; //value prepared for heading.

super(); //execute group heading.

The following code segment illustrates how the report query is duplicated into a QueryRun object.
qrHead = new QueryRun(element.query());

Demo

We will create a simple report with CustTrans as the only data source to demonstrate the highlighted approach. We dissect the whole process into three sections. The first will cover creating report while the second is regarding adding subtotal just to verify the outcome of the calculation. The final section is the one that cover the approach recommended. Those that are well versed with Dynamics Ax reporting tool may opt to skip the first two sections.

Create Report

The following steps cover report creation. Alternatively, you may use the Report Wizard to perform this.
  1. Create a new project to group objects if you have not.
  2. Right click on your project and select New > Report. You will have a report with the name Report1 created.
  3. Right click on Data Sources > Query > Data Sources and select New Data Source. Change the Table to CustTrans under the Property Page.
  4. Expand the node CustTrans(CustTrans) and right click on the node Sorting. Select New > Field. Ensure the Field is AccountNum. Change the properties AutoHeader and AutoSum to Yes.
  5. Right click on the Designs node and select New Report Design. You will see a new node named ReportDesign1 with a child node named AutoDesignSpecs.
  6. Right click on ReportDesign1 and select Generate Design. You will see a node named Generated Design added. You will also see a node named Section Group: CustTrans too.
  7. Expand the Section Group: CustTrans and right click on Body:CustTrans_Body. Select New Control > Field Group from CustTrans. Change the field group's DataGroup property to AutoReport.

Validation preparation

The following steps add a subtotal to a field for verification.
  1. Change the AutoFieldGroupOrder property to "Save the fields' properties" for the field group.
  2. Expand the Group and find control named Real: CustTrans_AmountCur and change the SumAll property to Yes.
  3. Right click on Footer: CustTrans_Footer and select New Control > Sum. Change the properties of the newly added for Table to CustTrans and Field to AmountCur.

Sum at Header

You now have a report with subheading. The following steps demonstrate the approach mentioned earlier.
  1. Add the following declaration to classDeclaration of the report. The classDeclaration will now look like the following.
  2. public class ReportRun extends ObjectRun
    {
      AmountCurDebCred  mrSum;
      QueryRun          qrHead;
    }

  3. Add a new method to Header: CustTrans_Header and copy the following code to it.
  4. display AmountCurDebCred SumAmtCur()
    {
      return mrSum;
    }

  5. Then add a new a control with the display method to the Header. This could be done by dragging the method and dropping it at the Header: CustTrans_Header node.
  6. Override the method executeSection() of the header with the following code. The method CustTrans_Header:executeSection() shall looks like the following.
  7. public void executeSection()
    {
      CustTrans  custTransLoop;
      real       rSum;

      // dupplicate the query on first execution of the header.
      if (!qrHead) {
        qrHead = new QueryRun(element.query());
        qrHead.next();
      }

      // loop as long as within the same subheading group.
      do {
        custTransLoop = qrHead.get(custTransLoop.TableId);
        if (custTransLoop.AccountNum == CustTrans.AccountNum) {
          rSum += custTransLoop.AmountCur;
        }
        else {
          break;
        }
      } while (qrHead.next());

      mrSum = rSum; //prepare value to be shown at group header.

      super(); //execute the group header.
    }


Source :http://axassociate.blogspot.in/search?updated-max=2008-03-20T14:28:00Z&max-results=3&start=9&by-date=false

Run External Application from Dynamics Ax


Calling up external program from Dynamics Ax can be something very interesting to audience during introductory training and demo. Once in a while, I will encounter associates asking if it is possible to run external program, open word document, open a URL in an external browser, etc. from within Dynamics Ax. Usually they will show a sign of immense enthusiasm when I show them how it is achieved. It is like their imagination is exploring all sort of creative ways to make use of this facility.
The interesting part is that executing external application is fairly effortless in Dynamics Ax. X++ is capable of calling Microsoft Windows Application Programming Interface (API). The common functionalities of the Win API have been built in classes WinAPIWinAPIServerWinGDI andWinInet. Running external application could be achieved through the static method WinAPI::shellExecute.

Static Method WinAPI::shellExecute

This method takes six parameters where five of them are optional parameters. The following code segment shows the interface of this method.
client static int shellExecute(
    Filename _lpFile,
    str      _lpParameters      = '',
    str      _lpDirectory       = '',
    str      _lpOperation       = #ShellExeOpen,
    int      _show              = #SW_SHOWNORMAL,
    boolean  _waitForCompletion = false
    )

The interface might look complicated but the first parameter is usually all we need to assign. It is sufficient to achieve most of the scenarios. The second parameter allows us to execute an executable with parameters. We will look at examples where this second parameter comes into play later.

Class SysShellExecute

The class SysShellExecute facilitates calling WinAPI::shellExecute. This class has a main method that call the method WinAPI::shellExecute using args.parm() as the first parameter. This enables WinAPI::shellExecute to be called from menu item with ease. This is important Dynamics Ax bring up windows through menu item. Menu item works with buttons with ease.
The following figure shows the property dialog of a menu item using SysShellExecute. The menu item shown will open an Internet Explorer browser when executed.
SysShellExecute Menu Item Property

Opening a File or URL

You shall not encounter any issue running application with class SysShellExecute. However, I have received enquiry when it comes to opening a file or a URL. I do not want to go into the ways they have tried. Basically opening file and URL are equally simple.

1. Default Application

Windows has associated different file type to a default application. We just need to execute the file name in order to open that file with the default application. The following figure shows the property page of a menu item that opens the website Dynamics Ax Associate in the default browser.
Open URL with SysShellExecute Menu Item

2. Specific Application

The previous approach opens the file or URL in the default application. There are cases where you need to specify the application to open the file with. You may achieve this with static method WinAPI::shellExecute.
Let say the default browser for your computer is FireFox and the website you are opening requires Internet Explorer. You may use the following code to open the URL with Internet Explorer.
WinAPI::shellExecute("IEXPLORE.EXE",
    "http://axassociate.blogspot.com");

Conclusion

The examples given above cover the execution of Windows Internet Explorer and opening of URL. They work similarly with a Word Document, Excel Spreadsheet, etc.

Source : http://axassociate.blogspot.in/2008/03/run-external-application-from-dynamics.html

Thursday, November 22, 2012

Classes, Tables, Forms and Methods used to post the sales orders


SalesTableType and SaleslineType classes will get called while creating the orders.
SalesFormLetter* classes will be used to post the sales order at various document status(packing, invoice etc).
SalesParm* tables are used to prepare the data for posting
CustConfirmJour, CustConfirmTrans - when a sales order gets confirmed
CustPackingSlipJour, CustPackingSlipTrans - when a packing slip is posted.
CustInvoiceTable,CustInvoiceTrans - when an invoice is posted.
These are some of the maily used tables.

Friday, November 2, 2012

Make Form/Report run automatically when dynamics Ax Starts

When ax starts Kernel Creates an instance of Info class . 
Info contains StartupPost() method used to execute the code every time ax starts.

Following example opens InventTable Form automatically when you start ax.

void startupPost()
{
SysSetupFormRun formRun;
Args args = new Args();
;

args.name(formstr(InventTable));
formRun = classfactory::formRunClassOnClient(args);
formRun.init();
formRun.run();
formRun.detach();
}

So if you have any task that has to be executed every time ax start , then this is the best place to put your code.

Source : http://learnax.blogspot.in/search?updated-min=2010-01-01T00:00:00-08:00&updated-max=2011-01-01T00:00:00-08:00&max-results=50

Axapta(X++) Glossary with their definition

Widely used Axapta Terms and their Definition

ALC

Microsoft Dynamics AX Label Description files have the extension .alc. Also see ALD and ALI. 

ALD

Label data files have the extension .ald (AX Label Data). Also see ALC and ALI. 

ALI

Microsoft Dynamics AX Label Index files have the extension .ali. Also see ALC and ALD. 

AOS

Application Object Server is windows service used to coordinate with different components of Dynamics Ax. 

AOT

Application object tree , repository that stores metadata information about the objects created in Axapta.

Base data

Data which is customer-dependent. Examples: Customers, Vendors, Items. 
This is often data from an existing system, which must be entered or imported into 
Microsoft Axapta. 


Control

Graphical object, such as a text box or command button that you put on a form or 
report to display data, perform an action, or make the form or report easier to 
read. 

CRUD

An abbreviation for the four basic database operations: Create, Read, Update, 
Delete. 

DCOM

Distributed COM 

Default data

Data which is customer-independent. Examples: Zip codes, Address formats, Time 
Intervals, Units, Unit conversions, VAT parameters, Transaction texts. 
Note 
When a user modifies default data, it becomes custom data, which is customer- 
dependent. This means that default data can sometimes be customer dependent, 
because of historic reasons, such as Chart of Accounts. 

Domain 

Collection of one or more companies. Domains enable you to define user groups that 
have the same permissions in more than one company while allowing the same user 
groups to have other permissions within other companies. 

EDT

Extended Data Type: a user-defined data type based on a primitive data type or 
container. 

IDE

Integrated Development Environment. MorphX is the Microsoft Dynamics AX IDE. 

IntelliMorph

The Runtime Environment embedded in Microsoft Dynamics AX, that draws menus, forms, 
and reports for Windows- and Web-clients with the correct contents, size, and 
layout according to: 
the language your texts are displayed in. 
what features you can access. 
how wide you want the fields on your installation. 
the formats you are using for dates and numbers. 

MorphX

The Development Environment of Microsoft Dynamics AX, including: 
Data Dictionary 
Tools for creating menus, forms and reports for Windows- and Web clients 
Compiler and debugger for the object oriented programming language X++ 
Version control system 
Label (multi language text) systems 

Overload

Provide more than one method with the same name but with different signatures to 
distinguish them. 
Overloading is not supported by X++. Also see override. 

Override

Replace the superclass's implementation of a method with one of your own. The 
signatures must be identical. 

Note 
Only non-static methods may be overridden. 

Record ID 

A record ID uniquely identifies a row of data in a table. Record IDs are integers. They are assigned and managed by Microsoft Dynamics AX. 

super () 

Reference to the system class that contains the required method. When super() is used, the system method is automatically used. 

this 

Reference to the current object. this is frequently used as a parameter to methods 
that need an object reference.for e.g at Table level if it used gives you the 
selected record. 

TTS 

Transaction Tracking System. For more information, see Transaction Integrity. 

WinAPI

Windows Application Programming Interface. Contains System level API's 
like "WinAPI::shellExecute("file.exe");" for opening applications from axapta.

Source : http://learnax.blogspot.in/2010_01_01_archive.html

For Ax Developers

Keep following things in your mind before you start coding in Ax.

1. Whenever you came accross new functionality , don't start coding immediately please first cross check whether the same/similar kind of functionality is there in the standard product. By doing so you will save time for coding,learn ax coding style and also this will help you to understand the various functionalities in the standard product.

2. Start with pseudo-code , just draw sketch on paper how you want the data to flow , which will help you in understanding the different override methods in Axapta.

3. Code should be modular , Instead of writing all the code in one method please write plug and play functions.

Source :http://learnax.blogspot.in/2010_01_01_archive.html