web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Auto Populate Field in...
Power Pages
Answered

Auto Populate Field in Lookup New Entry

(0) ShareShare
ReportReport
Posted on by 34

Hello,

I have a form which contains a lookup field to another table, and the users have the ability to enter a new record onto that lookup field. In the add form for the lookup field, I want to auto populate a field using the signed in user's details.

I know how to make use of liquid and jQuery to auto populate fields, but my issue here is that the schema name of the field that I want to auto populate in the add new entry of the lookup form is the same name as another field in the original form. They are both named "new_name" and I cannot change the schema name of a field, so when I perform the jQuery the field in the original form gets auto populated instead of the field in the lookup new entry form.

 

Is it even possible to auto populate a field in the add new entry of a lookup field or should I explore other options?

 

Thank you.

Categories:
I have the same question (0)
  • Saud Ali Profile Picture
    812 Super User 2024 Season 1 on at

    Hi @RCSI_SIA_BAH ,

     

    Yes, it is possible to populate a field in add new entry of a lookip field using jQuery/JavaScript. Can you please confirm if you're adding your script to add new entry form not on your main form?

     

    If you have to populate fields on add new entry form script will go there. Please check and share. If possible you can also post some reference screenshots.

     

    Thanks,

    Saud

     

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • RCSI_SIA_BAH Profile Picture
    34 on at

    HI @saudali_25,

     

    I'm using the script within the web template of the main form's page. I am not sure how I can include the script in the add new entry form as it is an iframe of a form.

     

    I tried using other selectors in jQuery for the field in the add new entry form but got no results so I'm wondering if there's a place where I can find and enter in the script for the iframe of the add new entry form.

     

    Thanks,

  • Verified answer
    RCSI_SIA_BAH Profile Picture
    34 on at

    Hi @saudali_25,

     

    After much testing and researching, I have figured it out. I just did a trial and error run of find elements on the page with jQuery until I could find the best combination to track down the field in the iframe and add a value to it.

     

    So the format I have used is:

     

    $(document).ready(function(){
     
    //This find can be trimmed down to a few but this was used during the testing
        var lookupModal = $("#lookupfield_lookupmodal").find(".entity-lookup").find(".modal-lookup-create-form").find(".modal-dialog").find(".modal-content").find(".modal-body").find("iframe").eq(0);
     
    //on load function of the iframe to update the field after the iframe has loaded
        lookupModal.load(function(){
            var newEntryField=  $(this).contents().find("#content-container").find("#field_id").eq(0);
        newEntryField.val(random value);
        });
    });
     
    Thank you
  • Fubar Profile Picture
    8,487 Super User 2026 Season 1 on at

    I wound not recommend running script from the underlying page, to update a modal basic form.

     

    The Basic Form itself has an area to add Custom JavaScript (you will find it if you use the Portal Management App) - if you use this you will not have conflicts with field names etc. 

    https://learn.microsoft.com/en-us/power-pages/configure/basic-forms#additional-settings

     

    If all you were wanting was to populate from a field on the Contact record you could do it either via other settings on the Form definition or by using a Metadata record for the Form (can pre-populate or populate on save)

    https://learn.microsoft.com/en-us/power-pages/configure/configure-basic-form-metadata

    https://learn.microsoft.com/en-us/power-pages/configure/configure-basic-form-metadata#prepopulate-field

     

    From the Basic form, you can also call the JavaScript that is sitting in a Template but need to reference it via parent/window objects.

  • RCSI_SIA_BAH Profile Picture
    34 on at

    Hi @Fubar ,

    That makes sense and sounds more reliable, however, does the custom JavaScript recognize Liquid variables that we may have created in the parent page?

    Also, is pre-populating fields from the Metadata section an alternative way to doing it by jQuery if we are just fetching data from a table?

     

    Thank you.

  • Fubar Profile Picture
    8,487 Super User 2026 Season 1 on at

    Metadata would only work where you need to populate data off the current logged in user, a static value or the system time.

     

    Liquid is not directly available in the modal forms JavaScript.  But in the main Web Page Content or the Web Template you  should be able to define a variable and then access that variable from the Basic form javascript 

     

    // If you were pulling field values to the modal form it would be something like
    
    window.parent.document.getElementById("new_name").value;
    
    or 
    
    $('#new_name', window.parent.document).val();
    

     

     

    For a variable using Liquid you would populate a JavaScript variable from Liquid in the Web Page Contenct or Web Template, and then in the Modal Forms JavaScript reference that variable

     

    // this is off the top of my head - I am not sure if it would be sitting on window.yourvarianble or
    // window.parent.yourvariable but something like
    
    //in Web Page or Web template
    <script>
     var yourvariable = "{{ user.fullname }}";
    </script>
    
    //In the javascript on the basic form
    alert(window.parent.yourvariable);

     

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
11manish Profile Picture

11manish 54

#2
Valantis Profile Picture

Valantis 46

#3
rezarizvii Profile Picture

rezarizvii 43

Last 30 days Overall leaderboard