Filtering Lookup Fields in Power Apps Portals Based on Another Field's Value
Introduction
In Power Apps Portals, a common requirement is to dynamically filter a lookup field based on the value of another field on the form. This functionality enhances the user experience by presenting contextually relevant choices, thereby streamlining data entry processes.
Scenario Overview
The requirement was to filter a lookup field named Reason
based on the value of a checkbox field Non-Booked Case
. The challenge was to implement this dynamic behavior in Power Apps Portals, where form configurations and behaviors are managed differently compared to Dynamics 365 CRM.
Challenge: Dynamic Field Behavior in Power Apps Portals
Initial attempts to use conditional logic in JavaScript to control the visibility and content of the Reason
field led to rendering issues. Specifically, duplicating the Reason
field on the form to represent different filtered states caused conflicts, as Power Apps Portals expects unique identifiers for each field.
Solution: Utilizing Two Lookup Fields with Different Views
To address this challenge, the following approach was adopted:
Create a Second Lookup Field: A new field (
ConditionalReason
) was created, targeting the same entity asReason
.Configure Different Views in CRM: Different views were configured for each lookup field in Dynamics 365 CRM. These views were used to filter the data shown in each field.
Implement Conditional Logic in JavaScript: JavaScript was used to toggle the visibility of the
Reason
andConditionalReason
fields based on theNon-Booked Case
checkbox value. This approach ensured that only one of the fields was visible at any time, depending on the context.
Implementation: JavaScript Code
The following JavaScript code was used to implement this solution:
Explanation
Visibility Toggle: The function
toggleFieldsBasedOnNonBookedCase
checks the state of theNon-Booked Case
checkbox and toggles the visibility ofReason
andConditionalReason
accordingly.Clearing Lookup Fields: The function
clearLookupField
resets both the display and the hidden input components of the specified lookup field.Event Listener Initialization: The script initializes by setting the visibility state and attaches an event listener to the
Non-Booked Case
checkbox for any changes.
Conclusion
This solution effectively demonstrates how to dynamically filter lookup fields in Power Apps Portals based on another field's value. By utilizing two lookup fields with different views and implementing conditional logic in JavaScript, the portal can provide a responsive and context-sensitive user experience. This approach also underscores the importance of understanding platform-specific behaviors and limitations when customizing Power Apps Portals.
How was the challenge of dynamically filtering a lookup field named Reason based on the value of a checkbox field Non-Booked Case addressed in Power Apps Portals, and what specific solution approach was adopted to achieve this dynamic behavior? visit us Telkom University
ReplyDelete