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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How can I set the defa...
Power Pages
Suggested Answer

How can I set the default value of a lookup column

(2) ShareShare
ReportReport
Posted on by 338
Hi there
 
A choice column has an option to set a default value, but a lookup column doesn't.
 
A basic form has a option to 'Prefill this field' for a text column but not for a lookup column.
 
There is an option to 'pre-populate field' when when adding (attribute) metadata to a basic form, but it doesn't seem to work with a lookup column (I've tried adding the text or the ID).
 
Hence, I wondered if anyone else has managed to set the default value of a lookup column and, if so, how?
Categories:
I have the same question (0)
  • MJWhite Profile Picture
    338 on at
    Adding reply as otherwise it doesn't show on default sort (have reported this and understand it will be fixed)
  • Suggested answer
    Fubar Profile Picture
    8,352 Super User 2025 Season 2 on at
    Without JavaScript/JQuery you are generally limited to either:
    • populating the Lookup that is the parent table - this is set on the Basic Form under Associated Table Reference, and to prefill you first need to set the On Save to Yes, and then tick the Populate Lookup Field
    • populating a Lookup to the current user Contact, or another Lookup from a Lookup that is on the current user Contact.
    With JavaScript/JQuery you can populate a Lookup if you have (or can get) the guid and name values to populate the Lookup with (e.g. get via Liquid table direct access or use fetchxml, or use the Portals Web API)
    There may be some typos in the bellow but something like
    // fieldSchemaName = the lookup field
    // guid = guid of the record to populate
    // name = value in the Primary Column of the record to populate
    // tableSchemaName = Table schema name of record being populated
    
    function populateLookup(fieldSchemaName, guid, name, tableSchemaName){
        $("#"+fieldSchemaName+"_name").val(name);
        $("#"+fieldSchemaName).val(guid);
        $("#"+fieldSchemaName+"_entityname").val(tableSchemaName);
    });
     
  • MJWhite Profile Picture
    338 on at
    Thanks @fubar
     
    The first option looks the most attractive, but it 'hangs' looking for a relationship (see screenshot below):
     
     
    There's definitley a relationship between the Account table and Country table (see screenshot below taken from Country column on Account table):
     
     
    Any ideas on how to eliminate the 'hanging'?
     
     
  • Suggested answer
    Inogic Profile Picture
    1,135 Super User 2025 Season 2 on at
    Hi,
     
    You can prepopulate the Lookup field with given three options in the Basic Form Metadata for a specific Entity Form,



    You can still extend this functionality by setting the default value to the lookup field in the Power Pages.

    Please follow the steps given below.
     
      • We will leverage the jQuery (JavaScript).
     
      • The lookup Column in Power Pages Contains three Inputs Record Name, Record GUID, and Entity Name.
     
      • We have to set three of the input fields to set the default value to the lookup field in the form.
     
      • Navigate to the Power Pages Management > Basic Form > Choose your Form > Additional Settings Tab > Custom JavaScript
     
      • Please refer to the screenshot given below.



     
    • Please use and update the code snippet below with your default values for the lookup field.

    $(document).ready(function(){
    //Record Name
    $("#lookupfiledid_name").attr("value", ‘Jhon’);
    //Record GUID
    $("#lookupfiledid").attr("value", ‘156ttdee-57be-ed11-83fe-002248ecdeed’);
    //Table Name
    $("#lookupfiledid_entityname").attr("value","contact");
    });

    This way, you can set the default value to your required lookup field in the Power Pages.

     
    Hope this helps.
     
    Thanks!
    Inogic Professional Services: Power Platform/Dynamics 365 CRM
    An expert technical extension for your techno-functional business needs
    Drop an email at crm@inogic.com 
    Service: https://www.inogic.com/services/ 
    Tips and Tricks: https://www.inogic.com/blog/ 
  • MJWhite Profile Picture
    338 on at
    Thanks for the help.
     
    I've tried both suggestions for javascript without success.  One generic question is whether it will work if the lookup is rendered to a dropdown or do I need to take that off?
     
    Then some specific quesions about each suggestion:
     
     
    Does lookupfiledid need to be replaced and if so with what?
    If the primary column of the table being lookup is no longer called name, does lookupfiledid_name need to be renamed?
     
     
    Should name, guid and tableSchemaName be in '  ' or "  "?
    If the primary column of the table being lookup is no longer called name, does _name need to be renamed?
     
    Thanks again
     
     
  • Suggested answer
    Inogic Profile Picture
    1,135 Super User 2025 Season 2 on at
    Hi,
     
    The code provided in the previous reply will work with the lookup default component, It will prepopulate the lookup values On-load of the form in Power Pages and will be saved in the record On-save.


    Please find the code below and update it as per your requirement,

    $(document).ready(function(){
    //Record Name
    $("#lookupfiledid_name").attr("value", “Jhon”);
    //Record GUID
    $("#lookupfiledid").attr("value", “156ttdee-57be-ed11-83fe-002248ecdeed”);
    //Table Name
    $("#lookupfiledid_entityname").attr("value","contact");
    });


    Save and Sync the Power Pages Site to the reflected changes.
     
    Hope this helps.
     
    Thanks!
    Inogic Professional Services: Power Platform/Dynamics 365 CRM
    An expert technical extension for your techno-functional business needs
    Drop an email at crm@inogic.com 
    Service: https://www.inogic.com/services/ 
    Tips and Tricks: https://www.inogic.com/blog/ 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 74 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 55

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard