I have been building PCF control since the early days of this Power Platform Component. Even now, after 5 years of using it, I keep finding interesting challenges. In this case, it was linking and filtration of the data based on the further-then-1 hop way from the “main” dataset entity.
Challenge
Let’s consider the following data model – the “main” dataset entity is “Quote”, “Quote” references “Accounts” through “Customer” lookup, “Account” references “Users” through “Key Account Manager” lookup, “User” has the “Territory” lookup. The task is to filter Quotes based on the Territory selected in the filter. The relationship diagram will look like the following screenshot:

Analysis
Historically, I haven’t built a lot of Dataset bound controls so I didn’t have experience extending links through the code. My first GoTos in this case are articles by amazing Diana Birkelbach (thanks, Diana, I learned a lot from your articles) and Microsoft Learn. Usually, I’m able to find an answer in one or another resource. But seems this scenario was outstanding and I was not able to solve the issue using these resources. According to Microsoft Learn, to access “linked” entities one has to use context.parameters.<Dataset Name>.linking object and according to Microsoft Learn there are only 2 operations available – addLinkedEntity and getLinkedEntities:

I was puzzled because according to the description of the Linking interface, it was possible to either add a new linked entity or get the list of the linked entities that were already added to the link. In other words, it was not possible to manipulate with linked entities, and what was even worse – it was not possible to perform the links that are deeper than 2 levels. So, I created the first prototype of the component and dived into Browser Developer Tools.
Solution
As usual, I have to warn you, my dear reader, that the code that I was able to compose might be considered unsupported so, please, use it taking the fact into consideration.
The first thing that I found were the “clear” and “removeLinkedEntity” methods of “Linking” that made it possible to dynamically remove/remove all linked entities from the dataset:

That was the first part of the puzzle I wanted to solve so I targeted the second part – performing the linking from linked entities. I slightly updated the code of the control adding the first link from “Quote” (root entity type) to “Account”, reloaded the browser, and checked developer tools again
|
1 2 3 4 5 6 7 |
context.parameters.Records.linking.addLinkedEntity({ name: "account", from: "accountid", to: "customerid", alias: "quoteaccount", linkType: "inner" }); |
Here is what I saw in the Developer Tools:

“linking” was exactly what I was looking for and based on the signature it was a match to the “linking” of the root Dataset object. So in other words in order to perform link to the next User table I will use the following code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
context.parameters.Records.linking.addLinkedEntity({ name: "account", from: "accountid", to: "customerid", alias: "quoteaccount", linkType: "inner" }); const accountLink = context.parameters.Records.linking.getLinkedEntities().find((e) => e.alias === "quoteaccount") as any; const accountLinkLinking = accountLink.linking as DataSetInterfaces.Linking; accountLinkLinking.addLinkedEntity({ name: "systemuser", from: "systemuserid", to: "custom_kamid", alias: "accountsystemuser", linkType: "inner" }); |
As a bonus, I found “filtering” in the list of available properties so I was able to set the join filter using the following code:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
const systemUserLink = accountLinkLinking.getLinkedEntities().find((e) => e.alias === "accountsystemuser") as any; const systemUserLinkFilter = systemUserLink.filtering as DataSetInterfaces.Filtering; systemUserLinkFilter.setFilter({ filterOperator: 0, conditions: [{ attributeName: "territoryid", conditionOperator: 0, value: "Put the territory id here" }] }); |
Conclusion
As you may see – having some time for research, a little luck, and attention to detail might bring unexpectedly successful results. My goal was to make it work in Model Driven Apps. I doubt it would work in Canvas or Power Pages because the data querying works the other way in those apps. Is it supported – I don’t think it might be considered supported but it worked perfectly for my scenario so it might work for you as well.