How to filter view in Power Apps portals/ Dynamics 365 portals with logged in contact

Follow Debajit’s Power Apps & Dynamics 365 Blog on WordPress.com

It’s been sometime I wrote a blog on portals and this topic is one of the requirements we come across frequently while implementing a portal solution. While this is a pretty old concept, many who haven’t worked with Dynamics 365 portals and just started working with PowerApps portals are not aware of this.

Let’s look at the requirement first. The requirement here is to filter the lookup view of account with the logged in portal contact.

A bit more explanation. There is N:N relationship between Account and Contact. A contact can be associated with more than one account. Quite simple requirement I shall say.

Now the requirement from portal side. There is an account lookup on an entity form. Whenever a contact login to the portal and select an account from an account lookup on portal, the lookup view should only show the accounts associated with the logged in contact.

As difficult it may sound, this is fairly easy and a trick is there which many are not aware of. So let’s see how we can achieve this.

Since the lookup view of the account is shown by default, we will go ahead and modify the lookup view of account from customizations area in CDS. You need to edit the appropriate view in case you are not showing the lookup view by default.

Observe the related entity condition here. I have taken the N:N relationship between Account and Contact and then applied a filter for a contact. You might be wondering – “Haven’t we hardcoded the contact here?“.

Well, the answer is Yes. We have but that’s where the beauty of portal lies. When this query will be executed on portal, the contact filter value shall be replaced with the contact who have logged in the portal.

And now when the contact try to select an Account using the lookup view in portal, the records will be filtered on the logged in contact record. While this example is with accounts and contact, the same can be set up between any custom entity and contact.

A quick note before I end this blog –

“Whenever you are inserting a contact filter specifically for the purpose of filtering the view based on logged in contact, it’s always suggested to create a separate view dedicated for the portal which won’t be used in CDS/ Dynamics 365.”

The dynamic replacement part will not work in CDS/ Dynamics 365 and hence lead to unexpected results.

You may also like the below posts

Hope this helped!

Debajit Dutta
Business Solutions MVP


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading