Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Design & Build
Suggested answer

Power page forms

(0) ShareShare
ReportReport
Posted on by

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,

 

Categories:
  • Suggested answer
    Jon Unzueta Profile Picture
    746 on at
    Power page forms
     

    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:


    Goal:

    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.


    Steps to Implement:

    1. Enable JavaScript on the Form

    In Power Pages:

    • Go to your form in the Design Studio.
    • Under Advanced, enable Custom JavaScript.

    2. Add JavaScript to Fetch Contact Details

    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);

                }

            );

        }

    }

    🏷️ Tag me if you have any further questions or if the issue persists.
    ✅ Click "Accept as Solution" if my post helped resolve your issue—it helps others facing similar problems.
    ❤️ Give it a Like if you found the approach useful in any way.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Pages - Design & Build

#1
oliver.rodrigues Profile Picture

oliver.rodrigues 33 Most Valuable Professional

#2
Fubar Profile Picture

Fubar 22 Super User 2025 Season 1

#3
JB-10040341-0 Profile Picture

JB-10040341-0 18

Overall leaderboard

Featured topics