*** NOTE: ALL INFORMATION IS ACCURATE AT DATE OF PUBLISHING ***
Anyone using Model-driven Apps is pretty much guaranteed to use Accounts and Contacts. There is a relationship between the two tables out of the box. A contact can be linked to an Account via the Company field, and can also be set as the Primary Contact via a lookup field on an Account. If you are using a custom page that you are opening from an Account, you might have a need to filter and display the related Contacts rather than allowing users to access or see a list of all Contacts in your system. This simple approach will give you a filtered list of the related Contacts as soon as the custom page is opened, making it a quick and easy user experience. Let’s take a look!
It really begins with the OnStart. I typically follow the approach of getting the Account GUID, then using that to filter the Contacts table. So first, make sure you have your Account and Contact tables in the custom page. I’ve shared an example of what I use below that you can copy and paste. the part of Set varRecordItem allows us to do testing while we are building the custom page. Change out the GUID you see in the script with the GUID of an Account in your own environment. Because we are building and not yet viewing from an Account, that means we can still view a working custom page. Once we’ve added it to a model-driven app and can open from a record, it will pass through the record ID from the Account we are on. Then we set another variable to get the whole record using the GUID from the varRecordItem variable, and setting the Account record as the varSelectedRecord variable.
Finally, the ClearCollect section creates a collection called ContactsList by filtering the Contacts table to find all those where the Company Name value on the Contact is the Account in the varSelectedRecord variable, and also makes sure to only get those that have a status of Active. We are sorting by last name ascending.
Set(
varRecordItem,
If(
IsBlank(Param("recordId")),
GUID("0e77fc9f-15ef-ec11-bb3c-002248005fd0"),
GUID(Param("recordId"))
)
);
Set(
varSelectedRecord,
LookUp(
Accounts,
Account = varRecordItem
)
);
ClearCollect(
ContactsList,
SortByColumns(
Filter(Contacts,'Company Name' = varSelectedRecord And Status = 'Status (Contacts)'.Active),
"lastname",
SortOrder.Ascending
)
);
You are likely using a Combo box that you have created, or one as part of a form like you see below. The concept is similar. I want to be able to set the Primary Contact, or see if one is already set for the Account. So on the Default control of the combo box, set it to varSelectedRecord then the Primary Contact field. If there is already a Primary Contact, it will be displayed.
Then in the Items for the combo box, add in the name of the Collection you created, in my case the ContactsList collection.
On the combo box, click on the properties and then Edit for the fields. Make sure you have the field selected that you want to use to display and also search on (if you have that turned on for the field).
You can then change the colours for how it will look if you want to.
And here we have the finished drop down (combo box). It shows the Contact already set, but gives me the ability to click and select a different person from the list if I need to change it.
Check out the latest post:
Create An Event Invitation Process In Customer Insights Journeys
Considering Custom Pages?
Thinking about using Custom Pages but unsure where they fit best?
I help organisations design model-driven experiences that are intuitive, scalable, and built for real users, not just technical possibility.
This is just 1 of 591 articles. You can browse through all of them by going to the main blog page, or navigate through different categories to find more content you are interested in. You can also subscribe and get new blog posts emailed to you directly.






