{"content":"In the latest release of the LookupDropdown PCF control for Dataverse, I have added a new feature that adds support for related record filtering, hence the ability to filter the values of a dropdown in real-time based on the value of another lookup field. When rendered, this can produce nice cascading effect as seen below.\nIn this post I will show how to configure the PCF control for this scenario and dissert on what\u0026rsquo;s happening under the hood to make the magic happen.\nTo get more context on the control, have a look at my initial post on the LookupDropdown PCF and be sure to install the latest version ( v1.0.0.3) to leverage this new feature.\n🚨 UPDATE 2022-03-10 : please use v1.0.0.4 or above of the control, a bug 🐛 was found for the filtering in v1.0.03\nBetter UX with a Lookup Dropdown PCF Control https://github.com/drivardxrm/LookupDropdown.PCF/releases/latest Lookup Dropdown PCF | PCF Gallery Use case To illustrate the feature, let\u0026rsquo;s pretend that we run a SpaceFlight scheduling service 🚀. As seen below, we have a data model that consists of Space Agencies and their corresponding fleet of Space Ships.\nNow in our SpaceFlight scheduling form, we want to exposes 2 lookups and we want to filter the values exposed in the SpaceShip lookup depending on the selected Agency.\nStep #1 : Configure Record Filtering At this point, I assume that you have already setup the Lookup Dropdown PCF control on the 2 lookup fields as described in my initial post. The next steps are only required when you want to implement dependent lookup filtering on top of that.\nThe platform natively exposesmechanism to provide additional filtering options on a lookup field. Therefore, the PCF control will make use this information at run-time to implement proper filtering.\nYou will need to open your form in classic mode as the Modern form editor doesn\u0026rsquo;t expose Record filtering yet. Now click on the Lookup field that you want to filter, in our case the SpaceShip field.\nIn the Display tab of the lookup field properties, go to the Related Records Filtering section. Enable the \u0026rsquo; Only show records where\u0026rsquo; checkbox and select the appropriate filters, Space Agency in our case.\nUsing the normal lookup ( without any PCF control), this would render something like this on the form, showing that the filters are well configured.\nStep #2 : Configure the PCF Control There\u0026rsquo;s new optional parameter defined in the LookupDropdown PCF manifest called \u0026rsquo; Dependent Lookup Field\u0026rsquo; that needs to be configured. The parameter expects a reference to a Lookup.Simple field.\nJust go to the Controls tab of the field properties, select the Dependent Lookup Field and from the list select the same lookup attribute that is part of the Related Records Filtering that was set in step #1. ( here the space agency field)\nWith a Dependent Lookup Field being configured, the control is able to resolve the Id (guid) of the dependent attribute at runtime. Most importantly, it also ensures that the instance of the PCF control gets notified 📣 whenever the dependent value gets updated. This makes certain that the filtered list gets updated as well.\nThats all there is, the SpaceShip dropdown will now expose the fleet of the selected agency and the values will automatically be updated when needed, as seen below.\nUnder the hood For developers, I think its interesting to show how the different pieces are used inside the code. Please refer to the code repo to get the latest implementation.\nI gave a good explanation in my first post on the way the control generates the query needed to render the control properly. Heres a recap :\nGet the default view id using the getViewId() method exposed by the lookupfield parameter Get the default view fetchxml by retrieving the record from the savedquery table Modify the fetch xml by adding the fields needed by the control (ex. entity image) Execute the modified fetchxml to retrieve the values needed by the control instance Without dependent lookup filtering, the query the SpaceShip lookup in the example would look something like this\n\u0026lt;fetch version=\u0026#34;1.0\u0026#34; mapping=\u0026#34;logical\u0026#34;\u0026gt; \u0026lt;entity name=\u0026#34;driv_spaceship\u0026#34;\u0026gt; \u0026lt;filter type=\u0026#34;and\u0026#34;\u0026gt; \u0026lt;condition attribute=\u0026#34;statecode\u0026#34; operator=\u0026#34;eq\u0026#34; value=\u0026#34;0\u0026#34;/\u0026gt; \u0026lt;/filter\u0026gt; \u0026lt;attribute name=\u0026#34;driv_spaceshipid\u0026#34;/\u0026gt; \u0026lt;attribute name=\u0026#34;driv_name\u0026#34;/\u0026gt; \u0026lt;attribute name=\u0026#34;driv_image\u0026#34;/\u0026gt; \u0026lt;/entity\u0026gt; \u0026lt;/fetch\u0026gt; Now, when dependent lookup filtering is enabled on the control, we need to add a link-entity node to the fetchxml and refetch the data everytime the valueof the dependent changes. In green you see the dynamic values that we can get using info from the configuration steps explained earlier.\n\u0026lt;fetch version=\u0026#34;1.0\u0026#34; mapping=\u0026#34;logical\u0026#34;\u0026gt; \u0026lt;entity name=\u0026#34;driv_spaceship\u0026#34;\u0026gt; \u0026lt;filter type=\u0026#34;and\u0026#34;\u0026gt; \u0026lt;condition attribute=\u0026#34;statecode\u0026#34; operator=\u0026#34;eq\u0026#34; value=\u0026#34;0\u0026#34;/\u0026gt; \u0026lt;/filter\u0026gt; \u0026lt;attribute name=\u0026#34;driv_spaceshipid\u0026#34;/\u0026gt; \u0026lt;attribute name=\u0026#34;driv_name\u0026#34;/\u0026gt; \u0026lt;attribute name=\u0026#34;driv_image\u0026#34;/\u0026gt; \u0026lt;link-entity name=\u0026#34;driv_spaceagency\u0026#34; from=\u0026#34;driv_spaceagencyid\u0026#34; to=\u0026#34;driv_spaceagency\u0026#34; alias=\u0026#34;dependent\u0026#34;\u0026gt; \u0026lt;filter type=\u0026#34;and\u0026#34;\u0026gt; \u0026lt;condition attribute=\u0026#34;driv_spaceagencyid\u0026#34; operator=\u0026#34;eq\u0026#34; uitype=\u0026#34;driv_spaceagency\u0026#34; value=\u0026#34;9ad553fc-a75f-ec11-8f8e-000d3a84327b\u0026#34; /\u0026gt; \u0026lt;/filter\u0026gt; \u0026lt;/link-entity\u0026gt; \u0026lt;/entity\u0026gt; \u0026lt;/fetch\u0026gt; The values needed to build the link-entity node can be obtained by extracting the dependentAttributeName and dependentAttributeType attributes of the bound lookupfield properties. These values will be filled accordingly as a result of Step#1.\n👉For a deep-dive the properties exposed by a lookup field have a look at this great post by Diana Birkelbach\nLookup PCF – let’s dive deeper – Dianamics PCF Lady (wordpress.com)\nAs for the ID (guid) of the dependent lookup, it can be found by looking at the dependentlookupfield properties. This value is defined as a result of Step#2.\nTakeaway I think that the Related Record filtering adds nice touch to the LookupDropdown PCF control. It certainly enables more use case to be ported and rendered by the control while providing a great user experience.\nIf you find any issues or have any comments/ideas for the controls please drop me a line in the discussion section of the repo.\nImage by jimmysobandith from Pixabay\n","date":"2022-02-09T02:37:48Z","image":"/related-record-filtering-with-the-lookup-dropdown-pcf/cars-g66f4a8d9d_1280_2.jpg","permalink":"/related-record-filtering-with-the-lookup-dropdown-pcf/","title":"Related Record Filtering with the Lookup Dropdown PCF"}