Pass Parent form ID and sellected record ids from a subgrid command button in Model driven power apps
You can pass Parent form ID and sellected record ids from a subgrid command button in Model driven power apps Follow below method.
Step 1 : Create a JS
function testParam(parentrecordid,subgridselectedids)
{
alert(parentrecordid);
alert(subgridselectedids);
}
Step 2 : Add Command Button & Call JS with Parameter
Now open the Model Driven App and Edit Command Bar. Select Subgrid command for Child Entity.
Make sure to select the command edit for child entity. Select Subgrid option and click Edit
Step 3 : Add a new command and call the JS library with parameter
Add a new command and specify name.
Set Visibility PowerFX to hide the command if no record is selected in the subgrid. In the Action command call the JS web resource and in function name add the function name from javascript file. Add two parameters.
- Parameter 1 – Primary Item Ids
- Parameter 2 – SelectedControlsAllitemIds
Now publis the Command and Model Driven APP. Now if you refresh and test on clicking the command button from subgrid you will see tow alerts.
First alert Parent record ID.
Second alert will diplay all selected records of subgrid with comma separated.
Now in JS you can add your own logic using the record IDs.
Hope this helps. This use case is used mostly for Cloning records.