cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Jqueen1
Frequent Visitor

Pre-populate form lookup-value using query string parameters

Hi there, 

 

We have a use-case which requires the use of a QR code to direct a user to a pre-populated form in a Power Pages website. The QR code will contain a link with some query string parameters that relate to the form. The field that needs to be populated is a Lookup value. For example, we need to pre-populated the Product field on a form which creates a new ProductEnquiry row in the ProductEnquiry table. The Product field is a lookup on the Product table. 

I can pre-populate the email address and other text-based fields of the ProductEnquiry form using JavaScript-> See Solved: Populate fields in form - Power Platform Community (microsoft.com)

I can also use this method to prepopulate the hidden html form fields related to the Product field. 

  • product_name
  • product (The GUID of the product)
  • product_entityname (The name of the Product table)

I would like to know if there is a better way of doing this in Power Pages? 

 

Kind Regards, 

Jason. 

3 REPLIES 3
OliverRodrigues
Super User
Super User

the best way would be via JavaScript




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.

Power Pages Super User | MVP


Oliver Rodrigues


 

Thanks Oliver, 

 

Using this method requires the name and entity name to be passed as query string parameters as well. Ideally, I would like only the entity's GUID to be passed in and the other attributes can be looked up automatically. 

For example:

var record = $("tr").find(`[data-id='${PID}']`);
if(record) {
    $("#cr0a1_product").val(record.attr("data-id"));
    $("#cr0a1_product_name").val(record.attr("data-name"));
    $("#cr0a1_product_entityname").val(record.attr("data-entity"));
}
else {
    console.log(`Unable to find Product with ID: '${PID}'`);
}

 
The code does work but only after the "Launch Lookup Modal" button next to the Product Field on the form is clicked. When clicked, a request is made to the following URL: https://example.powerappsportals.com/_services/entity-lookup-grid-data.json/{ENTITY_GUID}. This then populates the table in the modal with the available Product Entity records.  I have tried to call this endpoint using AJAX without much success yet. 

Do you know if there is any easy way of retrieving this information on page load (and without having to load the modal)? 

Thanks, 
Jason.

Fubar
Solution Sage
Solution Sage

Create a custom Web Template

Get the GUID from the REQUEST 

 

 

 

{% assign id = request.params['id'] | escape %}

 

 

Have a FetchXML statement to retrieve the Name (you already know the entity type as you are just dealing with products), or just load the Record itself directly as you already have the GUID

 

 

 

//below is for an account but you will get the idea
{% assign account = entities.account['936DA01F-9ABD-4d9d-80C7-02AF85C822A8'] %}
{{ account.name }}

 

 

 

You can achieve the same with JS, but the retrieve of the Name may cause a longer screen 'flicker' as you have to wait (document.ready) for the DOM to be created before calling your Ajax to do the population vs with a Web Template the values are retrieved server side and so the user is not waiting on the Ajax call.

 

There are 2 approaches if using Ajax (do not call endpoints you did not create)

(Note: in both the JS approaches you would use JQuery document.ready and then run your code inside it.  I don't know for sure but it feels like you may be trying to populate the Lookup before the DOM is created)

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Users online (2,309)