How to populate parent lookup field during create of child record from sub-grid in Power Apps portals.

Creating a child record from the subgrid of parent record form – a task which we perform in DataVerse Model-driven apps almost everyday and in every implementation.

And whenever we click on “+” icon of the subgrid, the child record form open and it has the parent lookup automatically set. I don’t think I need to explain it anymore. A simple video would suffice.

In Power Apps portals too, we can configure subgrids for Basic forms (previously entity forms). Below is an account basic form in portal where I have the contact sub-grid to add a child contact to the account

populate parent record lookup on child entity form/ basic form in powerapps portals.

When I click the ‘Create’ button on the sub-grid, unfortunately in the contact form which pop’s out the account is not automatically set.

populate parent record lookup on child entity form/ basic form in powerapps portals.

Which is rather surprising isn’t it? Afterall the portals and Model driven apps are so same in behavior, we kind of take these functionalities for granted. And yet there are these small functionalities which surprises us every now and then.

Well, that’s a problem. How do we fix it? The below fix shall work if you are opening the contact basic form (entity form) as modal dialog. I guess you can take this idea, tweak the code here and there and fit your scenario too.

When you open a record in portals, you will find the record id as query string parameter.

populate parent record lookup on child entity form/ basic form in powerapps portals.

So in my child form, if I can take the id parameter value which is the parent record id and then populate the lookup field of the parent on the child form, then everything should work fine. Let’s put that theory to code.

In the child basic form (entity form) onload, add the below javascript code.

$(window).on("load", function() {


var parentUrl=parent.window.location.href;

var id=parentUrl.split('=')[1];



//set the look up value. parentcustomerid is the name of lookup field. replace it with the lookup field name of your scenarion

$("#parentcustomerid_name").attr("value", "A. Datum Corporation (sample)");

$("#parentcustomerid").attr("value",id);

$("#parentcustomerid_entityname").attr("value", "account");



});

And below is the behavior post I do that.

Hope this helped. You will also like the below posts.

Debajit Dutta
Business Solutions MVP