Friday, November 30, 2012

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

X++ Code Optimzation

Following are the coding tips to improve your Axapta system's performance:
1. Smart Joins : Try to Use Joins instead of nested while loop 
wherever possible.
2. Select Statement : Mention the field names in the select statement 
instead of feteching entire row , this will reduce 
data amount to transfer from database.
e.g " Select Itemid from inventTable "

3. Display Methods : Make sure that generic display methods should be 
moved at table level and cached by 
using"Formdatasource.cacheAddmethod". 
4. Local caching : Use Variables for storing the constantly used 
caculated values in loop , by doing so you can 
reduce the calls to the database and different 
layers.
5. Monitor the Database Calls : For bulk records 
updation,deletion,insertion use 
RecordSet Based operator like 
update_recordset , delete_from and insert_recordset .
6. Aggregate Function: Use sum, avg, minof, maxof and count where 
applicable. Because this can utilize the database’s 
built-in function instead of calculating and analyse 
data in Axapta.

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