Thursday, December 18, 2008

Query or Not

I wanted here, nor the extended possibilities for the restrictions to give the best, but you can have everything ready for Axaptapedia read. 

 Therefore, initially only one thing I still would like to describe: 
Would be a restriction on an array of field (the dimension department, cost center, costs are a good example) can define these as follows created. 

queryRange = queryDS.addRange(fieldid2ext(fieldnum(InventTable, Dimension), 1
The draw of the range remains basically the same, only now using fieldid2ext nor the array index is specified. The index starts in Microsoft Dynamics Ax always on 1 

Now that this thing here is no longer treated, I would like a completely different way show records from the database in order to bring this example, in display screens. 

That will be a bit Tricky ... 
I begin today, but only "just" at. 

First we build us a new form and name this ArtikelSQL (The name is here eigendlich regardless, I have but for a mask decided article). 
Then we Invent the table using drag and drop a DataSource establish. At the conclusion, we show a few box (item number and article name ranges from first) on a newly added grid in this mask on. Ready - when calling the mask we get all the records in the table are Invent table. 

As a next step we define a variable in the Classdeclaration 

Source SQLAnweisung;
Before that, however, is made must be next, nor the method executeQuery on the DataSource overwritten. 
void executeQuery() {if (SQLAnweisung ( 
runbuf(SQLAnweisung, this .cursor());
else ( 
super();) 
) }

New is the IF query that checks whether a SQLAnweisung was created, or whether the variable SQLAnweisung is not empty. SQLAnweisung was not taken, the default query on the DataSource executed. Was but a SQLAnweisung is taken now instead of the query executed. 

Last but not least is missing only the SQLAnweisung, which must be created. 

void initSQLAnweisung()
{
XppCompiler compiler = new XppCompiler(); 
DictTable dictTable= new DictTable(Tablenum(InventTAble)); 
str SELECTAnweisung = 'SELECT * FROM '+dictTable.name();

SELECTAnweisung = ' void SQLSTMT('+dictTable.name() + ' '+dictTable.name() + ')\n{\n'+SELECTAnweisung+';\n}\n';

if (!compiler.compile(SELECTAnweisung))
{
setprefix( "@SYS57538" );
info (SELECTAnweisung);
error (compiler.errorText()); 
SELECTAnweisung = '';
}
}  This method creates the SQL statementIt is not enough simply a SELECT statement to write, because the compiler does not understand. Instead of a single SELECT statement writes simply a way around it, then the runbuf running. 
The SELECT statement is as follows and is equal to the variable SELECT statement assigned. 

SELECT * FROM InventTable 

This simple select statement we get all the records from the table Invent Table. At first glance, it is not easy to recognize but 

'Void SQLSTMT (' dictTable.name + () + '' + dictTable.name () + ') \ n (\ n' SELECT statement + + '; \ n) \ n';

 In view of readable

void SQLSTMT(InventTable InventTable) 
{
SELECT * FROM InventTable;
}
and global variables SQLAnweisung assigned. 
Only to be sent securely if everything were correct and contain no compilation, this statement yet about the compiler and compiled. 

compiler.compile(SQLAnweisung) 
No errors were found Primavera is everything, otherwise the variable yet cleared to run when the method executeQuery no mistakes to get. The output of the error by the compiler is optional. 

The call the method "initSQLAnweisung" method is still the super () in the init method of the mask. 
Through the SQL statement has the advantage in a very simple way and thus very complex queries design. There are some disadvantages also, unfortunately, the standard functions such as filtering, sorting or grading work in the above example, not more. 
Wie immer wurde auch dieses Beispiel in Microsoft Dynamics Ax 4.0 erstellt. As always this example was also in Microsoft Dynamics Ax 4.0. 

No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...