Auto-populating form fields from Dataverse

Loading

Power Pages allows you to auto-populate form fields based on existing data from Dataverse. This is particularly useful when you’re dealing with logged-in users, related records, or pre-existing values tied to a session or user profile. Here’s a step-by-step deep dive into how this works.


Common Use Cases

  • Pre-fill user profile forms with logged-in user details
  • Populate fields based on URL parameters (e.g., ?id=123)
  • Auto-load values from related tables (e.g., contact info from an account)
  • Enable seamless multi-step forms with field carry-over

Step-by-Step Guide

Step 1: Create Your Table in Dataverse

Ensure the Dataverse table contains the fields you want to populate. Example:

  • Table: CustomerFeedback
  • Fields: Name, Email, Phone, CustomerID

Step 2: Configure the Basic Form or Entity Form

  • Go to Power Pages Studio or Power Apps portal management.
  • Add or edit a form (Entity Form / Basic Form).
  • Select the table where the data resides.
  • Choose Insert Mode (for new records) or Edit Mode (for updating).

Step 3: Enable Pre-population Using Metadata

You can configure pre-filled values using one of these methods:


Method 1: Use Liquid to Auto-populate Logged-in User Info

In the web page where your form is embedded, use Liquid to get user details:

{% assign currentUser = user %}
<input type="text" name="email" value="{{ currentUser.emailaddress1 }}" />

If you’re using a Basic Form, you can include a hidden field pre-filled with a value using Liquid.


Method 2: Use Query Strings to Populate Fields

Pass values in the URL:

https://portalsite.com/form-page?email=user@domain.com&name=John

In the form configuration:

  • Go to the field’s Default Value
  • Use Request Query String as the source
  • Map email field to the email query string

This is a quick way to link data across pages or from external systems.


Method 3: Use JavaScript to Set Field Values on Load

You can use jQuery or JavaScript in the Custom JavaScript section of the form:

$(document).ready(function(){
$("#email").val("{{user.emailaddress1}}");
});

Or if you’re pulling from a FetchXML lookup:

fetch(`/_api/customers?$filter=contactid eq '{{user.id}}'`)
.then(res => res.json())
.then(data => {
if(data.value.length > 0){
$("#phone").val(data.value[0].telephone1);
}
});

Method 4: Using Metadata and Relationships

If your form includes a lookup field (e.g., to the Contact or Account table), configure the metadata to:

  • Set a default value from a relationship (e.g., logged-in contact ID)
  • Use a FetchXML query behind the form to return the default

Step 4: Secure the Experience

  • Ensure Web Roles and Table Permissions are configured to allow read access to needed tables and fields.
  • Avoid exposing sensitive data via query strings unless using encryption or server-side logic.

Pro Tips

  • Use Hidden Fields to carry values that users shouldn’t change.
  • You can also use Power Automate flows triggered on page load (via virtual table or form submission) to populate data dynamically.
  • Use Pre-fill Form Metadata JSON for advanced options.

Leave a Reply

Your email address will not be published. Required fields are marked *