Thursday, October 28, 2010

Query - A general approach

Query:
Query can be seen as a class interface for creating select statements.

  
Use a query in place of a select statement when the structure of the "select" (query) is not known until run time, or when the user should be able to specify the ranges.
In other situations, use a select statement. Select statements are often easier to read, and they are much more compile-time stable.

Queries are embedded in Forms, Reports and RunBase jobs and should always be used with these application objects, unless there are good reasons not to.

Queries are very flexible. Everything can be specified at run time, but specify as much as possible before run time. 

Create queries in the Application Object Tree (AOT) where possible, instead of building them in code.

Use intrinsic functions everywhere possible to enable compile-time checking of code.

The range of a query can be specified under program control by using two different techniques, the normal one and the query range value expression. Both take a string as an argument that is not evaluated until run time. The string must fulfill certain syntax restrictions and be as compile-time stable as possible.

Query Range value:

Always use the SysQuery::value method when you are programmatically assigning an atomic value to a query range.

Always use the SysQuery::range method when you are programmatically assigning a value range to a query range. The range method will supply the needed ".." operators.

Always use the SysQuery::valueEmptyString method when you want to have a range which must have a blank value.

Always use the SysQuery::valueUnlimited method when you want to have a completely open range.

Query Range value Expression:

Only use the query range value expressions if the normal query range values cannot be used.

Be aware that query range value expressions are evaluated only at run time (so they are not checked at compile time).

Because the contents of the Query range value expressions should look like X++, you should be careful to format the different data types correctly. Use the strFmt system function or queryValue/queryRange for this. queryValue and queryRange are methods on the Global class.

Place the expression in a range that is defined on the most relevant of the involved fields.

Tuesday, October 26, 2010

How to put Ax 2009 machine back to a clean state (remove the usr layer)

1. Stop the AOS (default service name is AOS50$01 for AX5).


2. Delete the user layer aod file (…\Microsoft Dynamics AX\50\Application\Appl\AXDB_App\axusr.aod) and *.aoi files.


3. Delete the metadata file in client %userprofile%\AppData\*.auc


4. Start the AOS.


5. Run AX client and do a synchronize on the Data Dictionary node on the AOT tree.