Dynamics AX Blog - Dynamics AX 2009 - Page 3

These posts are machine-translated.
Currently, only posts are displayed, which are relevant for Dynamics AX version »Dynamics AX 2009« Filter entfernen

RSS-Feed of this version

How to use an assembly/DLL in Dynamics AX

To use a DLL in Dynamics AX, the DLL must be added to the References node of the AOT.

This can be achieved by right-clicking on the node and select Add Reference. This opens a dialog where - depending on the "location" of the DLL - the following steps must be taken:

  • If the DLL is already registered in the Global Assembly Cache (GAC), it should already appear in the list where they can be selected using the checkbox on the left and selected with Select now.

    To register a DLL in the GAC, it is necessary that the DLL has been signed.
    They can be achieved via the command line using the following command
    "gacutil / i MyClassLibrary.dll"
  • If the DLL for example, is stored in the BIN directory of the client, you must first select it using the Browse button. Now they should appear in the list where they can be selected using the checkbox on the left and selected with Select.

In both cases, the dialog needs to be confirmed with OK.


 
 

Create word document by code

Microsoft WordBelow you will find a simple job, that creates a Word document containing a table. The example also sets the frame and the color of the table.
The example requires a locally installed Microsoft Word.

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:

Screenshot


 
 

How to create a AX<Table>-Class

If 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.


 
 

Example of a date filter in a form DataSource

The 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.


 
 

Print text-document using X++

Below you'll find a example, how to print a Text-document using X++.

static void printTextFileFromAX(Args _args)
{
    WinAPI::shellExecute("c:\windows\system32\NOTEPAD.EXE",  @'/pt "c:	emp	est.txt" "An OneNote 2010 senden"');
}

Note: "An OneNote 2010 senden" is the name of the printer.


 
 

Open a modal form

To call a modal form, the following code could be used (in clicked()-method of a button):

void clicked()
{
    FormRun formRun;
    Args args = new Args();

    super();
    
    args.name(formStr(MyFormName));
    args.record(SalesLine);

    formRun = classFactory::formRunClassOnClient(Args);

    formRun.init();
    formRun.run();
    If (!formRun.closed())
    {
        formRun.wait(true);
    }
}

Using this code, nearly every form could be opened in a modal way, so you have to close the form first before you will be able to return to AX.


 
 

Open form through code

Below you find some examples, how to open a form through code. Each example has it's own Advantages and disadvantages, but i think there is an example available for the most Scenarios.

static void openFormThroughCode_0(Args _args)
{
    menuFunction menuFunction;
    args args;
    CustTable custTable = CustTable::find('1101');
   
    args = new args();
    args.record(CustTable);
    args.formViewOption(FormViewOption::Grid);
   
    menuFunction::runClient(identifierStr(custTable), MenuItemType::Display, false, args);
}

 

static void openFormThroughCode_I(Args _args)
{
    FormRun formRun;
    args args = new args();
    args.name(formstr(CustTable));
    args.formViewOption(FormViewOption::Grid);
   
    formRun = classFactory.formRunClass(args);
    formRun.run();
    formRun.wait();
}

 
 
Pages « 1 2 3 4 5 » 

 

 
 
 
Posts of the actual month
April 2024
MoTuWeThFrSaSu
1234567
891011121314
15161718192021
22232425262728
2930 
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.