Global system functions like pickList(), pickUser()
and similar in Dynamics AX allow developers to build various lookups
displaying a list of custom options. Besides that, the standard Dynamics
AX application contains several additional global lookup functions,
which have a slightly richer user interface.
One of the functions is called selectSingle() and presents the user with a list of selectable options created using a container type variable.
In this
recipe for demonstration purposes, we will create a job that shows the
principle of how to use this function. As sample data, we will use
different versions of Dynamics AX.
How to do it...
1. Create a new job called SysListSelect:
static void SysListSelectSingle(Args _args)
{
container choices;
container sel;
boolean ok;
;
choices = [
["2009\nDynamics AX 2009",1,true],
["4.0\nDynamics AX 4.0",2,false]];
sel = selectSingle(
"Choose version",
"Please select Dynamics AX version",
choices,
["Version","Description"]);
ok = conpeek(sel,1);
if (ok)
{
info(strfmt(
"You've selected option No. %1",
conpeek(sel,2)));
}
}
2. Run the job to start the lookup:
3. Select one of the options, and click the OK button. The information message displays the selected option:
How it works...
In this recipe, we first fill in the choices
variable with values. Basically, here we build a container of
containers. Each container inside the parent container is made of three
elements and represents one selectable option in the list:
1. The first element is a selection text. Normally, it is displayed as one column, but in this example, we can use \n inside the text to create more columns.
2. The second element is the number of the list item. This value is returned upon user choice.
3. And the third value specifies whether the option is preselected by default.
Once list values are ready, we call selectSingle() to build the actual lookup. This function accepts five arguments:
3. A container of list values, in our case, choices.
4. A container representing column headings, in our case, Version and Description.
5. A reference to a caller object, normally a Dynamics AX form or control. In this example, we do not use this parameter.
singleSelect() returns a container of two elements:
1. true or false depending if the lookup was closed using the OK button.
2. The key value of the user-selected option.
There's more...
You may have noticed that the lookup, which is created using singleSelect(), allows choosing of only one option from the list. There is another similar global function called selectMultiple(),
which is exactly the same except that the user can select multiple
options from the list. The following code demonstrates its usage:
static void SysListSelectMultiple(Args _args)
{
container choices;
container sel;
boolean ok;
int i;
;
choices = [
["2009\nDynamics AX 2009",1,true],
["4.0\nDynamics AX 4.0",2,false]];
sel = selectMultiple(
"Choose version",
"Please select Dynamics AX version",
choices,
["Version","Description"]);
ok = conpeek(sel,1);
if (ok)
{
for (i=1; i <= conlen(conpeek(sel,2)); i++)
{
info(strfmt(
"You've selected option No. %1",
conpeek(conpeek(sel,2),i)));
}
selectMultiple() functionselectMultiple() functionabout}
}
Once the lookup is opened, you can select multiple options:
After clicking OK button, the information message shows selected options:
Note that here the second value of the returned container is a container of selected key values.