Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
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 230,214 Most Valuable Professional 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();
    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans