Dynamics AX Blog - Page 20
How to use an assembly/DLL in Dynamics AXTo use a DLL in Dynamics AX, the DLL must be added to the References node of the AOT.
In both cases, the dialog needs to be confirmed with OK. |
Create word document by code
static void CreateWordFileWithTable(Args _args) { COM wordApplication; COM wordTables; COM wordTable; COM wordSelection; COM wordTableRows; COM wordRange; COM wordTableCell; COM wordTableCellRange; COM wordDocuments; COM wordDocument; COM wordTableBorders; ; // Initialize Word object and document wordApplication = new COM("Word.Application"); wordDocuments = wordApplication.documents(); wordDocuments.add(); wordDocument = wordDocuments.item(1); wordSelection = wordApplication.selection(); wordRange = wordSelection.range(); // Get table collection wordTables = wordSelection.tables(); // Create table with 3 rows and 5 columns wordTable = wordTables.add(wordRange, 3, 5); // Fill cell: First line, second column wordTableCell = wordTable.Cell(1, 2); wordTableCellRange = wordTableCell.range(); wordTableCellRange.text("Hello"); // Fill cell: Second line, third column wordTableCell = wordTable.Cell(2, 3); wordTableCellRange = wordTableCell.range(); wordTableCellRange.text("World"); // Enable table borders wordTableBorders = wordTable.borders(); wordTableBorders.enable(true); // Add colored borders wordTableBorders.InsideLineStyle(3); wordTableBorders.OutsideLineStyle(5); wordTableBorders.OutsideColorIndex(2); // Get table row collection and add a new row wordTableRows = wordTable.rows(); wordTableRows.add(); // Open word wordApplication.visible(true); wordApplication.finalize(); } The created word document looks like this: |
AX 2012: Using computed colums to create subselectsUsing computed columns of view creates you the ability, to write subselects/subqueries. Find below a method, which is inspired by inventTable.productName() and can be used to display the name of an item. private static server str compColItemName() { #define.ViewName("ItemNameView") #define.DataSourceName("InventTable") #define.FieldItemId("itemId") #define.FieldProduct("Product") str sProduct; DictView dictView; str translationSQLStr; str productSQLStr; dictView = new DictView(tableNum(#ViewName)); sProduct = dictView.computedColumnString (#DataSourceName, #FieldProduct, FieldNameGenerationMode::FieldList, true); translationSQLStr = strFmt("SELECT Name FROM EcoResProductTranslation WHERE EcoResProductTranslation.Product = %1 AND LanguageId = '%2'", sProduct, CompanyInfo::find().LanguageId); productSQLStr = strFmt("SELECT DisplayProductNumber FROM EcoResProduct WHERE EcoResProduct.RecId = %1", sProduct); return strFmt("isNUll((%1), (%2))", translationSQLStr, productSQLStr); } |
How to create a AX<Table>-ClassIf you need a so called AX<Table>-class can use the class AxGenerateAxBCClass. Simply call this class in the AOT by right clicking and follow the wizard. A that way generated class must be modified sometimes, but using the wizard is much faster than creating the class manually. If the table changes, for example when adding new fields, you simply call that AxGenerateAxBCClass again and the AX<Table>-class will be extended accordingly. How to use such AX<Table>-classes, i've described here. |
AX 2012: Create a visual studio shortcut
The final shortcut should sim: After starting visual studio you can approve the used layer in the top of the application explorer.
|
Example of a date filter in a form DataSourceThe following code is an example of how to build a query range based on a Form Data Source, which displays only "daily" records. In the example the form-dataSource is named DataSourceName and it contains two date fields called FromDate and ToDate. Depending on a check box only records should be displayed, which that are valid for todays date. public void applyFilter()
{ queryBuildRange qbr; qbr = sysQuery::findOrCreateRange(DataSourceName_ds.queryBuildDataSource(), fieldNum(DataSourceName, recId)); if( !ShowExpiredCheckBox.checked()) { qbr.value(strfmt('('+ '((%5.%2 <= %1) && (%5.%3 >= %1)) || ' + '((%5.%2 == %4) && (%5.%3 == %4)) || ' + '((%5.%2 <= %1) && (%5.%3 == %4)) || ' + '((%5.%3 >= %1) && (%5.%2 == %4)) ' + ')', Date2StrXpp(systemDateGet()), fieldstr(DataSourceName, FromDate), fieldstr(DataSourceName, ToDate), Date2StrXpp(dateNull()), tableId2name(tableNum(DataSourceName)))); } else { qbr.value(SysQuery::valueUnlimited()); } } The above method can be called for example in the executeQuery() of the DataSource. |
|
|
|
|
|
|
I was asked this question recently and was not able to answer.
But i still knew that i had seen a page where this is explained in detail. But i knew neither find it manually nor using various search engines.
But in old documents of mine i found the source then, the trick to find it using search engines, is using the old name of Microsoft Dynamics AX - Axapta to look for it!
Do this, you will quickly find following page:
http://www.axaptapedia.com/index.php?title=Lookups