web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 127

#1
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 127

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 125 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans