Showing posts with label lookup. Show all posts
Showing posts with label lookup. Show all posts

Thursday, November 27, 2014

How to build a User List Lookup / Drop Down in AX 2009

User List Lookup / Drop Down
Step 1:Create a method in the form to get the user list lookup
void userListLookup(FormStringControl control)
{
    Args                args;
    MenuFunction        menuFunction;
    Object              formRun;
;

    args = new Args();

    menuFunction = new MenuFunction(menuitemdisplaystr(WorkflowUserListLookup), MenuItemType::Display);
    args = new Args(menuFunction.object());
    args.caller(element);
    args.parm(control.text());

    formRun = ClassFactory::formRunClassOnClient(args);
    formRun.init();
    formRun.run();
    formRun.wait();

    if (formRun.closedOk())
    {
        control.text(formRun.parmTo());
        element.redraw();
    }
}

Step 2: Call the method in the lookup event of the EDT
public void lookup()
{
    element.userListLookup(this);
}


Alternative Method: Just select WorkflowUserListLookup as formhelp on your EDT

Friday, July 17, 2009

Assiging a lookup method to a control

Question: I want to add a runtime control and override a lookup method of it.
Answer: I have created a tutorial on form that can be used for this purpose. The form adds a control at run time and override the lookup method of it at runtime.

The form can be downloaded from here.

Monday, March 24, 2008

Create Custom Lookups Dynamics AX

Question:
How can we create customized lookups in Dynamics AX
Answer:
One way of creating a custom lookup is by using the power of SysQuery. Lets solve this using a scenario, we want to create a customized vendor lookup that will be used on the Item form. We will define a vendor type and an item type and the vendor that matches the item type on the purchase order form shall be displayed in the lookup. So in order to get this output we will create a method lookupVendor() in the Vendor table and we will call this method from the overridden lookup() method of the Vendor.VendorId field of Vendor datasource passing in the item type from the form.
New method created in the Vendor table
public client static void lookupVendor(FormStringControl _ctrl,
VehicleVendorType _vehicleVendorType)
{

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(VehicleVendor), _ctrl);
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildRange vehicleVendorFuelFilter;
;
sysTableLookup.addLookupfield(fieldnum(VehicleVendor, VendorId), true);
sysTableLookup.addLookupfield(fieldnum(VehicleVendor, VendorName));
qbds = query.addDataSource(tablenum(VehicleVendor));
switch (_vehicleVendorType)
{
case VehicleVendorType::Fuel:
qbds.addRange(fieldnum(VehicleVendor, IsFuelVendor)).value(queryValue(NoYes::Yes));
break;
case VehicleVendorType::Mantienance:
qbds.addRange(fieldnum(VehicleVendor, IsMantenanceVendor)).value(queryValue(NoYes::Yes));
break;
case VehicleVendorType::Manufacturer:
qbds.addRange(fieldnum(VehicleVendor, IsFuelVendor)).value(queryValue(NoYes::Yes));
break;
case VehicleVendorType::Tyre:
qbds.addRange(fieldnum(VehicleVendor, IsManufacturer)).value(queryValue(NoYes::Yes));
break;
case VehicleVendorType::Vehicle:
qbds.addRange(fieldnum(VehicleVendor, IsVehicleVendor)).value(queryValue(NoYes::Yes));
break;
}
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}

Overridden method of Vendor.VendorId on Vendor Datasource

public void lookup(FormControl _formControl, str _filterStr)
{
;
VehicleVendor::lookupVendor(_formControl, VehicleVendorType::Fuel);
}