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 / Inserting values into ...
Power Pages
Answered

Inserting values into form fields

(0) ShareShare
ReportReport
Posted on by 147

Hi,

 

So I have a "Contact Us" form on my portal. On the form there is a look-up field to another entity called "Unit".

 

When the contact form is submitted it will create a lead in CRM and that's perfect. But I want to attach the look-up name onto the contact form for the unit, so that when the form is submitted it will already have look-up to the unit in CRM.

 

When I go to the contact form on the portal I have the unit primary name (look up name) in the request parameter, so I have the name available, I'm just not sure how to insert the value onto the form without having the user doing it.

 

So to clear things out:

 

I have a portal for showing all my units (apartments). You can go straight to a "contact us" page from the landing page or the navigation panel and create a lead in CRM (this form does NOT have the unit field). If you go into the "Unit" page it will show you all the units. From where you can pick a specific unit and that will navigate to a new page with a lot more details for this particular unit. On this detail page I have created a button called "Book Viewing" which navigates to a second "Contact Us" form (this form has the unit field as a read-only - essentially this field could be all hidden when things are working properly). The "Book Viewing button" sends the unit's primary name (look-up name) to the second contact us form in the request params, so I have the look-up name available I just dont know how to insert the value into the form field?

 

I have been using liquid a lot and believe this might be the way to do this but I'm not sure how.

 

 

Categories:
I have the same question (0)
  • Christian Leverenz Profile Picture
    1,214 on at

    Hi @oml ,

    when you have a lookup on the form, you have in fact three inputfields on the form. Lets say, yout lookup is primarycontactid then you have one input with the id "primarycontactid", one with "id="primarycontactid_entityname" and one with id "primarycontactid_label"

    The field without extension should get the id of the referenced entity, the _entityname, well, the logicalname/entityname of the target (e.g. "contact") and the _label is just what is displayed on the screen and should be set with something meaningful, so the user can see what is happening (if required).

    So, to make a lookup to a contact you need e.g. $("#primarycontactid").val("12345678-abcd-0123-9876-000000000000"); $("#primarycontactid_entityname").val("contact"); and $("#primarycontactid_label").val("the contactname"); 

    This should do the job.

    Do not forget:

    • the fields must not be disabled when submitting, else they will not be written
    • the authorization of your units to the primary entity has to allow "append" or "appendTo" (i will never get the direction in my life...)
    • it could be (not sure) that you also have to grant read right ob the referenced entity, but i'm not sure.

    Hope it helps,

    have fun,

      Christian

  • H V Profile Picture
    1,510 on at

    Hi @oml 

     

    Additional answer with @chleverenz,

    Please add below code in javascript section in Web page localized content.

     

    Suppose, your field logical name is "new_unitid".

    $(document).ready(function(){
    		$("#new_unitid_name").attr("value","Unit Name");
    		$("#new_unitid").attr("value","b27183ce-a8af-ea11-a812-000d3a579cb3");
    		$("#new_unitid_entityname").attr("value","uom");
    });

     

  • Christian Leverenz Profile Picture
    1,214 on at

    Well, i would rather use the val() function from jquery, but it should be the same as value is an attribute of the input.

    Does it work? -> everything ok 🙂

    If you do not want the lookup to be filled in the frontend, you could also write the id in a helperfield and write a short plugin which fills the lookup 🙂

     

     

    $(document).ready(function(){
    		$("#new_unitid_name").val("Unit Name");
    		$("#new_unitid").val("b27183ce-a8af-ea11-a812-000d3a579cb3");
    		$("#new_unitid_entityname").val("uom");
    });

     

    Keep on portalling,

      Christian

     

    PS ups, @hardikv : sorry, did not want to judge your code, thought it was a question - next time i will read before posting 🙂

     

  • l.oliver Profile Picture
    147 on at

    Thank you both, @chleverenz  & @hardikv , for your answers!

     

    Just to make sure before I head on doing a lot of stuff:

     

    My logical_name for the "Unit" entity is "crc17_propertyunit" and on the web template for the "contact us" page I have the following liquid code:

     

    {% assign unit = entities['crc17_propertyunit'][request.params.id] %}

     

    This is fetching the particular unit I need to apply as a look-up on the "contact-us" form.

     

    So I would need to make some javascript/jquery in the "Web page localized content" to insert the "unit.crc17_name" value onto my "Contact Us"-form in the Unit (look-up) field, so that when I submit the form a lead will be created in my system with the look-up to the particular unit already assigned?

     

    Example:

     

    $(document).ready(function(){
    		$("#unit.crc17_name").val("Name");
    		$("#unit.id").val("d8aff6bd-809a-ea11-a811-000d3ab4f1b4");
    		$("#unit.id_entityname").val("Property Unit");
    });

     

    I'm not sure about the last line - is this the actually name of the entity I created in my solution? And would it be 

    $("#unit.crc17_entityname").val("Property Unit");

    instead of 

    $("#unit.id_entityname").val("Property Unit");

     

  • H V Profile Picture
    1,510 on at

    Hi @oml 

    $(document).ready(function(){
    		$("#crc17_propertyunit_name").val("-----Unit Name-------");
    		$("#crc17_propertyunit").val("b27183ce-a8af-ea11-a812-000d3a579cb3");
    		$("#crc17_propertyunit_entityname").val("uom");
    });

    You need to add Unit Name of the record.

  • Christian Leverenz Profile Picture
    1,214 on at

    Hi together,

    if i got it right, you have a lookup to your units, what is a custom entity called "crc17_propertyunit" , right?

    The lookup has presumably the name "crc17_propertyunitid", right ? (not to be confused with the id in the entity crc17_propertyunit) 

    so the code should in my opinion be

     

     

     

    $(document).ready(function(){
    		$("#crc17_propertyunitid_name").val("-----Unit Name-------");
    		$("#crc17_propertyunitid").val({{ unit.crc17_propertyunitid.Id}});
    		$("#crc17_propertyunitid_entityname").val("crc17_propertyunit");
    });

     

     

     

     

    when the assign statement was something like {% assign unit = entities['crc17_propertyunit'][request.params['id']] %}

    For the real names of the field just open the page in chrome for example and with f12 look at the real name, this is usually the fastet way to see the ids of the fields 🙂 )

    The problem is a little bit the mix between liwuid and javascript. From the page or entityscripting, you can not use liquid. So, may be in liquid you would create hidden inputs or divs with the read values.

     

    Hope it clears things and hope i got it right,

      Christian

  • l.oliver Profile Picture
    147 on at

    Hey @hardikv ,

     

    Thanks for the quick reply.

     

    When I have this assign:

     

    {% assign unit = entities['crc17_propertyunit'][request.params.id] %}

     

    wouldn't the code look something like this:

     

     

     

    $(document).ready(function(){
    		$("#unit.crc17_name").val(" 'logical name of the field' ");
    		$("#unit.id").val("b27183ce-a8af-ea11-a812-000d3a579cb3");
    		$("#unit.crc17_entityname").val("uom");
    });

     

     

     

    Should the: 

    $("#crc17_propertyunit_entityname").val("uom");

    give me the same name as the entity has in the solution (in my case "Property Unit")?

     

    I now understand the javascript - please ignore the above.. 🙂

  • l.oliver Profile Picture
    147 on at

    Hi @chleverenz ,

     

    Thank you as well for the quick reply.

     

    You are correct, the unit is a custom entity called "crc17_propertyunit".

     

    I will try your code and get back with the result as soon as possible.

     

    Cheers!

  • Christian Leverenz Profile Picture
    1,214 on at

    Sorry for the spam, but: when you already have the crc17_propertyunitif (passed in as a parameter) why do you need to retrive the propertyunit again? you could just use the request.params.id, sore it in some hidden input or div and fill the lookup in the document ready. Or did i miss something?

  • l.oliver Profile Picture
    147 on at

    Hi @chleverenz ,

     

    I'm not sure if I understand your latest post?

     

    The request.params.id that it passed onto the Contact Us page is the ID of the specific unit record I need data from.

     

    So for me to be able to retrieve these field values from this specific unit, I would assign it like this:

    {% assign unit = entities['crc17_propertyunit'][request.params.id] %}

    and then I can just "dot" into the different fields I need, ex:

     

    Unit case no. : {{ unit.crc17_name }}
    Size: {{ unit.crc17_size }} m2 (squaremeters)
    Rooms: {{ unit.crc17_rooms}}
    Address: {{ unit.crc17_streetname }}
    City: {{ unit.crc17_city }}
    Postcode / Zip Code: {{ unit.crc17_zipcode }}

     

    Does it makes sense?

     

    Please let me know if I misunderstood something. 🙂 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 33 Super User 2026 Season 1

#2
Mohsin Ali Profile Picture

Mohsin Ali 25

#3
SP2019admin Profile Picture

SP2019admin 20

Last 30 days Overall leaderboard