web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Custom Lookup with filtering

(0) ShareShare
ReportReport
Posted on by

I have a form with a grid. I have a query I've created in the AOT that's assigned to the grid.

At runtime I want to be able to dynamically assign the range. How do I do this?


It's easy enough with a query built in X++ (QueryBuildDataRange), but I can't figure out how to do it with an AOT query.

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,670 Super User 2026 Season 1 on at

    Hi Pete,

    You can find many examples on search engines, have a look at next example.

  • Community Member Profile Picture
    on at

    Yes, I've looked at Google and through all the examples I've seen, I run into some issue or another that I can't seem to get around.

    The example you linked is one of them. They do the work in init(), but init() takes no parameters, so how do I pass the information I need to filter on?

  • Sohaib Cheema Profile Picture
    49,670 Super User 2026 Season 1 on at

    do you want to filter based on current selection by user, where user will select a value?

  • Community Member Profile Picture
    on at

    Actually, it's a lookup and it's called by 2 different controls and the what I'm looking for depends on which control is calling the lookup.

    And the reason I can't use SysLookup is that I need to display fields from 2 different tables in the query.

  • Sohaib Cheema Profile Picture
    49,670 Super User 2026 Season 1 on at

    If your lookup and controls are all on same form, you can always get values of controls in current form/context. It seems you have written code of lookup not on the form, but somewhere on the table level. You can pass FormStringControl  as 1st parameter, in case if you lookup method is on any table.

    But if your lookup method is on the form, you can take current values of controls by setting AutoDeclartion= True for those controls.

    This way based on caller you can change lookup code.

    Regarding your 2nd point, which is about usage of SysTableLookup, I would say you can use it in a way by creating a view by joining two tables, if that suits you.

  • Community Member Profile Picture
    on at

    While you can have a join in a query and create ranges on those joined tables, you can only display fields from a single table in a SysTableLookup (the one passed to newParameters()).

    As for your description of what to do, I'm confused.

    I have my main form which has all my data and the controls (let's call it myMainForm).

    Then I have my lookup form (let's call it myLookupForm).

    I override lookup() in the data source on the field associated with the controls I'm displaying the lookup for. The code look like this:

       FormRun formRun;

       Args args;

       args = new Args(identifierStr("myLookupForm"));

       formRun = classFactory::formRunClassOnClient(args);

       formRun.init();

       this.performFormLookup(formRun, _formControl);

    How do I pass my parameter to myLookupForm?

  • Sohaib Cheema Profile Picture
    49,670 Super User 2026 Season 1 on at

    if you are using lookup form you can always get calling control using below syntax and you can put your custom logic based on calling control

    callingControl = SysTableLookup::getCallerStringControl(element.args());

    I feel more comfortable to use lookup by x++ code by placing code on table level in such case, Doing that way you can pass parameters as below

    public void lookup(FormControl _formControl, str _filterStr)

    {

    TableName::lookupStaticMethodName(

    _formControl,

    AnyValueToPass);

    }

    You may have a look at next presentation to know what will suite you best.

  • Community Member Profile Picture
    on at

    But I can't use SysTableLookup::getCallerStringControl() because it's not a SysTableLookup.

    I have the FormControl object in the lookup() function (assigned to _formControl in the code from my previous post). How do I pass that to myLookupForm?

  • Sohaib Cheema Profile Picture
    49,670 Super User 2026 Season 1 on at

    attach your XPO here on community or somewhere, I will look into details what you are trying to do

  • Community Member Profile Picture
    on at

    I figured out how to pass the value. The value I'm passing is a LogisticsLocationRoleType.

    in the lookup() I have:

       args = new Args(identifierStr("myLookupForm"));

       cont = [LogisticsLocationRoleType::Consignment_IN];

       conClassObj = new ContainerClass(cont);

       args.parmObject(conClassObj);

       formRun = classFactory::formRunClassOnClient(args);

    Then, in the lookup form's init(), I'm doing:

       xArgs args;

       container cont;

       ContainerClass conClassObj;

       super();

       if(element.args())

       {

           args = element.args();

           conClassObj = args.parmObject();

           cont = conClassObj.value();

           roleType = conPeek(cont, 1);

       }

       element.selectMode(lookupControl);

    So that works great!

    So that gets me half way there. The only thing I need to do now is to set the range on the query in the datasource. How do I accomplish that?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

#1
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#1
Pratik Bhosle Profile Picture

Pratik Bhosle 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans