Recently we had a requirement for one of our Dynamics Portal projects that I thought we could share with the community. The requirement was pretty simple. We had a many to many relationships between Contact and Account (so that a contact could belong to multiple Organizations) that needed to be displayed in a dashboard.
The default out of the box relationship for Account of the Contact having a Scope of Contact, or even a Scope of account did not work, so we needed to set a Global Scope, basically exposing this to the Portal, but limiting what will be available using our own logic.
The image below shows the Entity Permission that we set, so that it would become global:
The next step that was needed was to design the fetchXml to retrieve all the accounts that are associated the portal logged in user. We needed to use the user.id liquid object. We created a Web Template that contained the following Xml. This would retrieve a list of all accounts that are associated with the Account Contact many to many manual entity, and display it on the Web page.
The first part of the web template, which includes the fetchXml is shown below. Notice the link-entity which contains the relationship between account and contact and the condition attribute set to the logged in user id.
The next part is retrieving all the accounts (if available). We loop through the list of accounts and display the account name, and other fields.
Finally, we can create a new web page based on a web/page template to view the results is our web portal.