Announcements
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
Hi,
This can be done by setDefaultView.
1. Go to form editor and turn off the View Selector for your User field.
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}"); } }
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156