Trigger FLOW From Gallery In PowerApps And Populate Data

Problem

Consider you are building an application where you need to enter details of multiple employees in the form, also need to populate their data like department, job title, employee code, etc automatically. You can easily get the employees profile data by using Office365Users connector. But you can’t get employee Id using this connector. So how can you get employee Id for the employees entered/selected in gallery on demand?

Solution

We can make a call to FLOW from gallery row input controls. Let’s build a FLOW first which will be triggered from control in gallery, in my case I need to get employee ID of selected employee. Refer below screenshot to understand what all actions are used to build a FLOW, you need to use Get User Profile action and select employeeId as field. Respond back with the output of that action using this expression

outputs('Get_user_profile_(V2)')?['body/employeeId']

Now, identify when do you want to trigger the FLOW, make sure you have the input parameter value ready before making the call. In my case in gallery row, I have combo box control to select user, on selection of user I need to trigger the FLOW to get the employee ID. This response from the FLOW I need to bind to textbox control in same row.

Challenge and wrong approach

Now another challenge here would be storing and binding the response to the textbox control in that specific row. If you use local or global variable to save the response of the FLOW and bind that variable to default property of textbox control, then the values would be overwritten by latest response.

UpdateContext({varEmpployeeId: GetEmployeeId.Run(comboBox.Selected.Mail).empCode}) OR
Set(varEmpployeeId, GetEmployeeId.Run(comboBox.Selected.Mail).empCode)

Check the below screen to see the effect of what happens if you use local variable to store the response of FLOW and bind to a control in gallery

Trigger FLOW from Gallery in PowerApps and Populate data

Correct approach and solution

To overcome the above issue, we must store the response of the flow in a local collection say CollEmpIDs (key value pair array) something like as shown below. Whenever we will trigger a FLOW, we will store a record in collection with selected employee email and response of FLOW which is employee ID.

Mail ID
[email protected] 111
[email protected] 222
[email protected] 333

Check the below screen to understand how you can add a key value pair in local collection to store the response of the FLOW. Key would be email address of selected employee and value would be employee ID (response from FLOW)

Trigger FLOW from Gallery in PowerApps and Populate data

Now the employee code textbox default property can be set to below expression. This will filter out the employee from local collection and show its employee ID.

First(Filter(collEmpCodes, Mail = comboBox.Selected.Mail)).ID

Trigger FLOW from Gallery in PowerApps and Populate data

Check out this YouTube video to see above configuration in detail.

This is how it looks when you select employees one by one and it triggers the FLOW and gets response back and binds it in gallery controls

Trigger FLOW from Gallery in PowerApps and Populate data

Summary

We have seen how we can make FLOW calls dynamically on change event of control from inside the gallery and store the responses in local collection, bind the response to a control in same row in that gallery. This is the approach we can use where bulk insert/updates are needed.

I hope this will help you guys. Thanks for reading.


Similar Articles