How to set up look-up values in the power apps portal

Recently in one of our projects, we came across a scenario in which there was a need to set up multiple lookup field values on the Entity Form. After conducting a simple Google Search, we came across a number of queries by developers — or by those who are into a little bit of cut-and-paste development — that were having trouble getting this done.

So, here it is. In this blog, we are going to show you how you can set up lookup field values through JavaScript on the Entity Form.

Step 1:

Right-click on the lookup field to inspect the element or press F12.

Step 2:

After clicking on “Inspect,” a Developer Command window will open. And from the Inspect Element window, we have to get the three-element IDs:

  • Name input ID: fav_parent1_name
  • Guid input ID: fav_parent1
  • Entity Name input ID: fav_parent1_entityname

As seen in the image below, we get the lookup-field ID as per our lookup-field. Your field ID will be unique to you.

Step 3:

Now we have to write the JavaScript code to set the lookup field value. Navigate to your respective webpage in Portal Model-Driven App => Open Localized Content Page => Open the Advance tab => In the Custom JavaScript section, we have to write our code.

Custom Code Syntax:

$(document).ready(function () {

//Contactname = String Value i.e. record name
//contactId= Guid of the record
//contact = entity name

In our scenario, we are retrieving the record values and dynamically passing the values through the variables. For this, refer to the below screenshot.

So, after clicking on the Save button on the Entity Form, the lookup-field value in the CRM will be as shown in the below screenshot.

On the Portal end, when you open a record in Edit mode, that record will display as seen below:

This is how, with the help of JavaScript, you can programmatically set the lookup-field value on the Entity Form.