Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

Restricting data in Lookup Field

Posted on by 10

The Organisation entity has amongst its records, organisations who are suppliers (there is an “organisation type” field that determines this).

There is a many-to-many relationship of organisations and organisations who are suppliers of theirs.

I have a lookup field in the Organisation entity called “Key Supplier” which I want to offer selection from only that organisations’ suppliers.

How do I go about creating this field and make it lookup from just organisation who are suppliers of the organisation being edited.

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Restricting data in Lookup Field

    Hi Savik,

    There are 2 ways to approach your requirement.

    1. OOB

    Navigate your Organisation entity and click its view menu, create a new view and Edit Filter Criteria, it will give filtered result with your criteria. (It's easy to edit) 

    pastedimage1564392951670v3.png

    Then in your Organisation form, select the Key Supplier field and edit it properties, scroll down to bottom and select the previous created view as Default View and set it to be only selected(presented) view in this Lookup field.

    pastedimage1564393211715v4.png 

    2. By script

    You could add Script with 2 client API to filter results in lookup field:

    they are addCustomFilter and addPreSearch function,

    the first function is to add our filter, while the second one calls our filter to work, you should combine them in same code logic.

    function filterOrganisationLookup() {  
        try {

            // Get the Key Supplier lookup field and apply our filter function to it.
            Xrm.Page.getControl("new_KeySupplier").addPreSearch(function () {
                addCustomLookupfilter();
            });
        } catch (e) {
            throw new Error(e.message);
        }
    }

    function addCustomLookupfilter() {
        try {

            // fetchXml is our criteria
            fetchxml = "<filter>" + "<condition attribute='new_organisation type"' operator='eq' value = 'Suppliers' />" + "</filter>";
            Xrm.Page.getControl(" new_KeySupplier").addCustomFilter(fetchxml, "new_organisation");
        }
        catch (e) {
            throw new Error(e.message);
        }
    }  

    Finally let filterOrganisationLookup function execute when Organisation Form OnLoad, 

    please read this article for how to add JavaScript to form.

    Notes:

    1. You should set parameter in getControl(" ") method to Name attribute to access your Lookup field.

    1830.png

    2. It's same for entity you add filter and its attribute. 

    7824.png

    Regards,

    Clofly

  • Suggested answer
    Aditya Profile Picture
    Aditya 260 on at
    RE: Restricting data in Lookup Field

    If your requirement is search the organisations in the “Key Supplier” lookup field based on the “organisation type”= Suppliers then you can use the presearch feature.

    On the “Key Supplier” Lookup field apply the presearch. Your  fetchxml statement would be retrieve the organisations whose “organisation type”= Suppliers.

    You can  refer the following link :-www-inogic-com.cdn.ampproject.org/.../

    Hope it helps!

    If the answer is useful to you, please mark it as verified.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans