Posted in: X++

Dynamics AX X++ function to get today's date

Posted on October 27, 2016 by Michael Roma

Use the follow function:


How to return a blank or empty date in X++ Dynamics AX 2009

Posted on July 28, 2015 by Michael Roma

The following function returns an empty or blank date in X++.

return datenull();

How to display the x++ stack trace using the InfoLog in Dynamics AX

Posted on March 16, 2013 by Michael Roma

Use the following code to display the x++ stack track through the InfoLog in Dynamics AX:


How to check if the current user is in a User Group in Dynamics AX

Posted on December 29, 2011 by Michael Roma

Use the following code:

boolean check = UserInfoHelp::userInUserGroup(curUserId(), "GroupName");

How to create a lookup in Dynamics AX that is conditional, based on a different field

Posted on December 29, 2011 by Michael Roma

In the example below, the lookup should be different based on the DRType field.

First create a function on the table where the field you want to have a lookup for, this case the table is called InventDR:

void orderIdLookup(FormControl _formControl)
    // function that shows the look for the dr type

    // define lookup form, and query
    SysTableLookup       lookupForm;
    Query                query = new query();
    QueryBuildDatasource qbds;

    // setup the lookup form and query
        // production
        case DRTypeBase::Production:

            // setup the form and query
            lookupForm = SysTableLookup::newParameters(tablenum(ProdTable), _formControl);
            qbds = query.addDataSource(tablenum(ProdTable));

            // add the lookup fields
            lookupForm.addLookupfield(fieldnum(ProdTable, ProdId));
            lookupForm.addLookupfield(fieldnum(ProdTable, Name));

        // purchase order
        case DRTypeBase::PurchaseOrder:

            // setup the form and query
            lookupForm = SysTableLookup::newParameters(tablenum(PurchTable), _formControl);
            qbds = query.addDataSource(tablenum(PurchTable));

            // add the lookup fields
            lookupForm.addLookupfield(fieldnum(PurchTable, PurchId));
            lookupForm.addLookupfield(fieldnum(PurchTable, PurchName));

        // anything else, quit

    // set the query

    // perform the lookup

Next, override the performFormLookup() function on the Form Datasource Field:

public void performFormLookup(FormRun _form, FormControl _formControl)
    // show the order lookup