ENTERPRISE

Microsoft Dynamics AX 2009 : Building Lookups - Displaying a list of custom options

11/17/2012 12:51:58 AM
When speaking about lookups, in most cases, we mean a list of data records presented to the user for selection. But sometimes, it is required to show a list of possible selection options that are "hardcoded" into the application or retrieved from an external system or file. Normally, it is a much smaller list of options as opposed to those of the data-driven lookups.

In this recipe, we will create such a lookup with a help of the global pickList() function. We use a Dynamics AX job, which will create and run the lookup.

How to do it...

  1. 1. Create a new job called PickList:

    static void PickList(Args _args)
    
    {
    Map choices;
    str ret;
    ;
    choices = new Map(
    Types::Integer,
    Types::String);
    choices.insert(1, "Dynamics AX 2009");
    choices.insert(2, "Dynamics AX 4.0");
    ret = pickList(choices, "", "Choose version");
    if (ret)
    {
    info(strfmt("You've selected option No. %1", ret));
    }
    }
    
  2. 2. Run the job for the results:

  1. 3. Double-click on one of the options:

How it works...

The lookups created using the global pickList() function are based on values stored in a map. In our example, we define a new map called choices and initialize it. The map keys are of type integer and values of type string.

Next we insert "Dynamics AX 2009" as the first option and "Dynamics AX 4.0" as the second. At this stage, the map is ready to pass it to pickList().

This function accepts three parameters:

  1. 1. A map, which contains lookup values. Here, we pass our choices variable.

  2. 2. A column header, which is not used.

  3. 3. A lookup title, which in our case is "Choose version".

The function returns a key value from the map, which could be used for further processing.

There's more...

The global pickList() function is a way of displaying generic custom data in the lookup. Besides that, standard Dynamics AX contains a number of other global lookup functions, which can be used for different purposes.

Companies

The global pickDataArea() function can be used to allow a user to select one of the Dynamics AX companies. But in order to use it, we first need to correct the function itself. In my version of Dynamics AX, it returns a DataArea type. However, it should return DataAreaId. Open the Global class in AOT, find pickDataArea(), and make sure the first line is:

static DataAreaId pickDataArea()

{
...

Restart the Dynamics AX client in order to apply the changes.

Next, create a new job called PickDataArea():

static void PickDataArea(Args _args)

{
DataAreaId dataAreaId;
;
dataAreaId = pickDataArea();
if (dataAreaId)
{
info(strfmt("You've selected %1", dataAreaId));
}
}

And run it:

Upon user selection, the function returns the selected company account number.

Domains

Another global method called pickDomain() can be used for choosing Dynamics AX domains. It is very similar to the previous example, and it also contains a mistake in its code. We need to change the line args.parm(' 10') to args.parm(' 9') in the pickDomain() function of the Global class in order to make it work. The modified method should look like this:

static domainId pickDomain()

{
Object formRun;
Args args;
;
args = new Args(formstr(SysPick));
args.parm(' 9');
...

Do not forget to restart the Dynamics AX client again. Once this is done, we can create a new job called PickDomain():

static void PickDomain(Args _args)

{
DomainId domainId;
;
domainId = pickDomain();
if (domainId)
{
info(strfmt("You've selected %1", domainId));
}
}

You should get the following result after the job is started:

The return value of the lookup is the Dynamics AX Domain ID.

User groups

The global pickUserGroup() allows us to present the user with a list of Dynamics AX user groups. It accepts a user ID as an optional argument. If this argument is present, the lookup will display only groups that this user belongs to, otherwise all groups. In the job code below, we list all the groups of the user who is currently logged in:

static void PickUserGroup(Args _args)

{
UserGroupId userGroupId;
;
userGroupId = pickUserGroup(curuserid());
if (userGroupId)
{
info(strfmt("You've selected %1", userGroupId));
}
}

And here is the result:

Users

Another global function called pickUser() shows a list of Dynamics AX users. The job below is used to demonstrate how it works:

static void PickUser(Args _args)

{
UserId userId;
;
userId = pickUser();
if (userId)
{
info(strfmt("You've selected %1", userId));
}
}

The result is a lookup with a list of all Dynamics AX users:

The pickUser() function can accept one optional argument of type Map, which contains a custom list of users. This might be useful when the lookup must show only some of the system users.

Tables

More advanced pieces of custom Dynamics AX functionality may require a user to select one of the application tables directly. An example in standard Dynamics AX can be Definition groups, which can be accessed in Administration/Periodic/Data export/import.

The global function pickTable() is the key element of this functionality. The following job demonstrates how it works:

static void PickTable(Args _args)

{
TableId tableId;
;
tableId = pickTable(false, true, true, false, false);
if (tableId)
{
info(strfmt(
"You've selected %1",
tableid2name(tableId)));
}
}

The result is a lookup with a list of Dynamics AX tables, which returns a table ID upon user selection:

pickTable() accepts five optional arguments, which drives the number of tables being listed:

  1. 1. Include data dictionary maps?

  2. 2. Include temporary tables?

  3. 3. Include system tables?

  4. 4. Include views?

  5. 5. Show only tables to which the user has access rights?

Table fields

A list of table fields can be displayed by using the global pickField() function. This function accepts a table ID as argument and presents the user with the list of fields of that table. The following job displays a list of fields of the LedgerTable table:

static void PickField(Args _args)

{
FieldId fieldId;
;
fieldId = pickField(tablenum(LedgerTable));
if (fieldId)
{
info(strfmt(
"You've selected %1",
fieldid2name(tablenum(LedgerTable),fieldId)));
}
}

The result is a list of LedgerTable table fields:

The lookup returns the selected field ID.

Classes

In even complex custom functionality, sometimes it is necessary to allow the user to specify a Dynamics AX AOT class directly. We allow helper functions here too. The following job demonstrates how the global PickClass() function can present a list of classes to the user for selection:

static void pickClass(Args _args)
{
ClassId classId;
;
classId = pickClass(false);
if (classId)
{
info(strfmt(
"You've selected %1",
classid2name(classId)));
}
}

And the job's result is a list of Dynamics AX classes:

The function accepts one optional argument, which allows us to include/exclude system classes. In the previous example, we exclude system classes by passing false as an argument.

Interfaces

The global function pickInterface() is very similar to the previous function, except that it shows a list of Dynamics AX interfaces. The job below demonstrates the usage of this function:

static void PickInterface(Args _args)

{
ClassId classId;
;
classId = pickInterface(false);
if (classId)
{
info(strfmt(
"You've selected %1",
classid2name(classId)));
}
}

And the result is a list of Dynamics AX interfaces:

This function also accepts one optional argument to include or exclude system interfaces.

Other  
 
Most View
Windows Vista : Build Your Network (part 1) - Terminology Primer, To Wire or Not to Wire
Amazon Kindle Fire HD - A Chunkier Tablet
Deconstructed - Five Classic Bass Music Tunes And Discover Some Key Ideas (Part 4)
Open GL : Storing Transformed Vertices—Transform Feedback (part 1)
How-To Computing: Upgrade Your Music With iTunes Match
SQL Server 2012 : Distributed Transactions (part 2) - Distributed Transactions in the .NET Framework
SQL Server :ONE-WAY ENCRYPTION - Creating the Interface (part 2) - Setting and Verifying Permissions to the Stored Procedures
Sharepoint 2010 : Planning for Governance (part 2) - What Is in the Governance Plan - Vision Statement, Roles and Responsibilities
Nvidia GeForce GTX 780 3 GB - A Large Increase Occurring In Every Aspect (Part 5)
Smartphone Tips - Quick Advice For Simple Problems (Part 2)
Top 10
SQL Server 2012 : Consolidating Data Capture with SQLdiag - Getting Friendly with SQLdiag (part 2) - Using SQLdiag as a Service
SQL Server 2012 : Consolidating Data Capture with SQLdiag - Getting Friendly with SQLdiag (part 1) - Using SQLdiag as a Command-line Application
SQL Server 2012 : Consolidating Data Capture with SQLdiag - The Data Collection Dilemma, An Approach to Data Collection
SQL Server 2012 : Troubleshooting Methodology and Practices - Data Analysis, Validating and Implementing Resolution
SQL Server 2012 : Troubleshooting Methodology and Practices - Data Collection
SQL Server 2012 : Troubleshooting Methodology and Practices - Defining the Problem
SQL Server 2012 : Troubleshooting Methodology and Practices - Approaching Problems
Windows 8 : Accessing System Image Backup and Recovery Functionality with Windows Backup, Cloud Backup
Windows 8 : Using the Windows 8 Recovery Tools (part 2) - Push Button Reset
Windows 8 : Using the Windows 8 Recovery Tools (part 1) - Creating a System Recovery Disc, Booting to the Windows Recovery Environment