Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Filter lookup views based on field value

(0) ShareShare
ReportReport
Posted on by 138

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,505 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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans