Hi there,
We’ve built a Power Pages form to allow users to submit extension requests for our department. (Please find a screenshot of the form attached.)The intention is that when a user selects their Contact from the lookup field, the rest of their details (e.g., email, phone, etc.) should auto-populate from their existing record in our CRM. However, we haven't had any success getting this to work so far. Is there a recommended way to achieve this? Ideally, if a contact already exists in the system and the user selects them from the Customer lookup, the form should automatically fill in their associated details, allowing them to simply review and submit.
Any guidance or suggestions would be greatly appreciated.
Kind regards,
To auto-populate fields on a Power Pages form based on a selected Contact from a lookup field, you can achieve this using JavaScript and Web API calls within Power Pages. Here's a step-by-step guide to help you implement this:
When a user selects a Contact from a lookup field, the form should automatically populate fields like email, phone, etc., from the selected Contact's record in Dataverse.
In Power Pages:
Here’s a sample script you can use:
// Replace 'contactid' with your actual lookup field name
// Replace 'email', 'telephone1', etc., with your actual field names on the form
function onContactChange(executionContext) {
var formContext = executionContext.getFormContext();
var contactLookup = formContext.getAttribute("contactid").getValue();
if (contactLookup && contactLookup.length > 0) {
var contactId = contactLookup[0].id.replace("{", "").replace("}", "");
Xrm.WebApi.retrieveRecord("contact", contactId, "?$select=emailaddress1,telephone1,firstname,lastname").then(
function success(result) {
formContext.getAttribute("email").setValue(result.emailaddress1);
formContext.getAttribute("phone").setValue(result.telephone1);
formContext.getAttribute("firstname").setValue(result.firstname);
formContext.getAttribute("lastname").setValue(result.lastname);
},
function (error) {
console.log("Error retrieving contact: " + error.message);
}
);
}
}
oliver.rodrigues
33
Most Valuable Professional
Fubar
22
Super User 2025 Season 1
JB-10040341-0
18