Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

Filter lookup views based on field value

Posted on by 134

Dear Team,

I am after an requirement to filter lookup views or show only certain records based on field value. I would like to know if this achievable via JS.

I have 2 views under User entity 'Sales Director View' and 'Sales Manager View'.

I have a field called 'Discount' and I have a lookup field called 'User' within the Quote entity. When the discount value is < 10% then I need to show only 'Sales Manager view' under the user lookup or only sales manager user records under the lookup.

if the discount is > 10% then similarly i need to show only 'Sales Director view' under the user lookup or only sales director user records under the lookup.

Please let me know if this achievable OOO or via JS.

Thanks 

Gowtham

  • Suggested answer
    Ray Profile Picture
    Ray 1,479 on at
    RE: Filter lookup views based on field value

    Hi,

    This can be done by setDefaultView.

    1. Go to form editor and turn off the View Selector for your User field.
    pastedimage1678413483935v2.png

    2. Write JS code using setDefualtView function to set the view when discount get changed, here is a code sample:

    function setDefaultViewSample(executionContext) {
        var formContext = executionContext.getFormContext();
        var discount = formContext.getAttribute("Discount").getValue();
        if (discount > 10) {
            // Sales Director view
            formContext.getControl("User").setDefaultView("{00000000-0000-0000-00AA-000010001003}");
        } else {
            // Sales Manager view
            formContext.getControl("User").setDefaultView("{00000000-0000-0000-00AA-000010001003}");
        }
    }

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,647 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans