Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Filtering Lookup Value

Posted on by

pastedimage1651053561412v1.png

Hello,

I want to lookup field Name where the IsTemplate value is only true, can anyone help me?

Should i using addRange or something?

Here's my code :

public void lookup()
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(Hierarchy), this);
    ;

    queryBuildDataSource = query.addDataSource(tableNum(Hierarchy));

    sysTableLookup.addLookupfield(fieldNum(Hierarchy, Name),true);
    sysTableLookup.addLookupfield(fieldNum(Hierarchy, Description));
    
    queryBuildRange = queryBuildDataSource.addRange(fieldNum(Hierarchy, IsTemplate));

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

  • faridz Profile Picture
    faridz on at
    RE: Filtering Lookup Value

    Thank you so much Martin it's solved now , sorry for late reply.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 225,588 Super User on at
    RE: Filtering Lookup Value

    You're almost done - you just need to set the value of your query range:

    public void lookup()
    {
        Query                   query = new Query();
        QueryBuildDataSource    queryBuildDataSource = query.addDataSource(tableNum(Hierarchy));
        QueryBuildRange         isTemplateRange;
        SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(Hierarchy), this);
    
        sysTableLookup.addLookupField(fieldNum(Hierarchy, Name),true);
        sysTableLookup.addLookupField(fieldNum(Hierarchy, Description));
        
        isTemplateRange = queryBuildDataSource.addRange(fieldNum(Hierarchy, IsTemplate));
    	isTemplateRange.value(queryValue(NoYes::Yes));
    
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,989 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans