Blog

shutterstock_2231710273 900 x 600

Set Lookups in Power Pages using JavaScript

Microsoft Power Pages is a low-code, secure, enterprise-grade platform for creating, hosting, and managing modern external-facing business websites. It is part of the Microsoft Power Platform family which also includes Power Apps, Power Automate, Power BI, and Power Virtual Agents.

What is Power Pages?

Power Pages is great because it allows you to create web pages with the familiarity of PowerApps. There are some limitations when using some of the out-of-the-box tools available for model-driven apps. One of these limitations include the lack of business rules. That means if you need to apply any logic to forms in power pages, you’re going to need JavaScript. Most of the time this is a simple enough thing to implement. However, one case where it isn’t so straightforward is when setting lookup columns. Let’s take a look at what it takes.

Adding JavaScript to Power Pages

To add JavaScript to a basic form you go to the bottom of the additional detail’s tabs. For multi-step forms, you go to the desired step and scroll to the bottom of the form options tab. Here, you can add some code that looks like this:


The third line will trigger the JavaScript whenever the form is loaded. The second will also trigger it whenever the columns with the logical name ‘btg_logicalname’ is changed.

Setting the Lookup

Now let’s look at how we can set a lookup. For most column types, setting the value is a simple line of code. For lookups, we need to use three. In the example below we are setting the customer column on a case. The first line will set the name of the customer. This is just the plain text name for the customer. The second will be the GUID. Finally, the third is where we set the table type the lookup is looking for. This may seem a bit heavy-handed for a lookup that points at a single table. However, the benefit is that we can use this code to lookups that can reference multiple tables such as customers and regarding lookups.

Contact Beringer Today!

We love to implement Microsoft Dynamics 365 and Power Platform solutions here at Beringer.  We’ve been working with Microsoft Dynamics since its inception, and we’re always finding innovative ways to implement the latest tools and help automate business processes.

Beringer Technology Group, a Microsoft Solutions Partner for Business Applications, specializing in Microsoft Dynamics 365 and CRM for Distribution also provides expert Managed IT ServicesBackup and Disaster RecoveryCloud Based Computing, Email Security Implementation and TrainingUnified Communication Solutions, and Cybersecurity Risk Assessment.