web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Filter lookup views based on field value

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Ray Profile Picture
    1,537 on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 197 Super User 2026 Season 1

#2
CU11031447-0 Profile Picture

CU11031447-0 100

#3
NeerajPawar Profile Picture

NeerajPawar 70

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans