Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How to build custom lookup based on field value ?

(0) ShareShare
ReportReport
Posted on by 205

Hi guys, 

I made this custom form, in there i need to make a lookup on red field, based on green field values.

On that form i got a datasource based on a custom table, where i have a field linked to bankaccount table on accountID (Red field) and another linked to data aread id (green field)

The red field will give on each row bankaccount accounts filtered on green field values representing data areas.

pastedimage1681979557284v3.png

I hope my requirement is understoodable.

How could i perform that ?

Thank you all.

  • GirishS Profile Picture
    GirishS 27,816 Super User 2024 Season 1 on at
    RE: How to build custom lookup based on field value ?

    We can use addCompanyRange but you can't say that legal entity is static. If there is any new legal entity added and new bank account added against the company, you need to modify the code also.

    You can use that as workaround but need to keep in mind of the above drawback.

    Thanks,

    Girish S.

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,550 Super User 2024 Season 1 on at
    RE: How to build custom lookup based on field value ?

    Please check this article, instead of query range use company range.

    https://wp.me/pbiV2U-1v

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: How to build custom lookup based on field value ?

    You want the query based on some other dataareaid which is not the UI dataareaid right. So you should use change company. Just check the same in inventtable or vendtable for example.

    Give changecompany and in that write this query.

  • Awaxx Profile Picture
    Awaxx 205 on at
    RE: How to build custom lookup based on field value ?

    Still the same issue, even i checked the cross company query to yes on datasource property.

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,550 Super User 2024 Season 1 on at
    RE: How to build custom lookup based on field value ?

    Can you change datasource property cross company query to Yes and check.

  • GirishS Profile Picture
    GirishS 27,816 Super User 2024 Season 1 on at
    RE: How to build custom lookup based on field value ?

    I think you need to have a query.allowCrossCompany(true) and then set the "Cross-company auto query" property to yes at form DataSource level.

    If it doesn't suit your scenario try creating cross company query with BankAccountTable as DataSource - Create a AOT view - Map that query to a view - Use that view in the lookup query instead of BankAccountTable.

    Thanks,

    Girish S.

  • Awaxx Profile Picture
    Awaxx 205 on at
    RE: How to build custom lookup based on field value ?

    public void lookup(FormControl _formControl, str _filterStr)
    {
        //Specify the name of the table the lookup should show data from.
        SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(BankAccountTable), _formControl);
        //Create a new query
        Query                   query = new Query();
        QueryBuildDataSource    queryBuildDataSource;
        QueryBuildRange         queryBuildRange;
        
        sysTableLookup.addLookupfield(fieldNum(BanAccountTable, AccountId));
        //join the datasource to the query;
        queryBuildDataSource = query.addDataSource(tablenum(BankAccountTable));
        queryBuildDataSource.addRange(fieldnum(BankAccountTable, DataAreaId)).value(queryvalue(DataSourceName.DataAreadId));
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }

    I was saying that its working with that code, but i got an error notification saying :

    Filtering at the data source level is not allowed for a cross-company query

    So i wanna know what to do to fix it ?

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: How to build custom lookup based on field value ?

    Your question is not actually understood. Can you please explain in more detail so that I can give my solution approach if possible?

  • Awaxx Profile Picture
    Awaxx 205 on at
    RE: How to build custom lookup based on field value ?

    Even i remove the line.

    If do that i have no values on field, only for the current company matching with it

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,550 Super User 2024 Season 1 on at
    RE: How to build custom lookup based on field value ?

    Can you try removing the line query.allowCrossCompany(true) from your code.

    If removing this line does not work then try this code on Form control (in FOrm Design) lookup instead instead of form datasource field lookup.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,540 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans