Track Assets/ Resources using Power Apps and Power Automate
In this post, I will show you how I built an automated Assets/ Resource tracker using Power Apps and Power Automate. I will use the Geo-Fence trigger in Power Automate to create a Flow template and invoke that to create a new flow with an updated Location on the trigger based on location inputs from Power Apps.
Let's Get Started!
The scenario that we are trying to build here is that a Field service person checks in at the site of work from a canvas app. This action then triggers a flow that first gets a template flow, creates another flow based on the template flow and sets the latitude and longitude parameters of the new flow's Geo-fence trigger from the inputs received from Power Apps.
The main flow is invoked from the button control in Power Apps. The current location is retrieved using the Location.Latitude and Location.Longitude functions. Expression used on the button control of the canvas app is:
Expression: Set(testvis, true ); Set(lat,Location.Latitude); Set(lon,Location.Longitude); Set(usr,User().FullName); 'Button->CreateFlow'.Run(lat,lon,usr)
Explanation: The visibility of the checkout button and a few labels is set via the 'testvis' variable. "lat", "lon" and "usr" variables are set for the "Latitude", "Longitude" and the name of the current logged in "User" respectively.
Now lets take a look at the flows built on Power Automate to complete this solution. We will first create a template flow and then use it to create the on demand location tracking flows. We will also create a main flow that will be triggered from Power Apps and get the template flow, add the changes to the trigger and finally create the new flow.
Step 1: Trigger: Location: This flow triggers when the device enters or exits a particular region. This region is configured by the latitude, longitude and the radius set on the trigger configuration.
Step 2: Action: Send an email notification: To send an email notification about the location check out. This notification includes the name of the flow so that the person monitoring this can identify the device from which the flow was triggered. The expression used to get the Flow name is:
Step 3: Action: Turn Off Flow: Once the checkout is complete and the email notification is sent, we want to turn off the flow. The expression used here to identify the ID of the current flow is:
Step 1: Trigger: Power Apps button: To trigger the flow from a Power Apps Button Control.
Step 2: Action: Get Flow: To get the "Geo-Fence Template Flow" template that will be used further to create the new flow with the modified trigger parameters corresponding to the Latitude and Longitude parameters sent from Power Apps.
Step 3: Initialize Variable: To store the latitude value.
Step 4: Initialize Variable: To store the longitude value.
Step 5: Initialize Variable: To store the name of the user that triggered the flow.
Step 6: Action: Create Flow: This is the most critical action of the entire setup. The JSON for the new flow is to be constructed and as we need to make some changes in the flow trigger parameters, the variable values are selected at respective places from the dynamic selector. As the actions needs to be same, we will reference that from the outputs of the "Get Flow" action from the dynamic selector.
Tip: Create a flow and add the action "Get Flow" to get the template flow. Copy the flow definition from the run history and construct the JSON with the customization for the new flow in the create flow action here.
Step 7: Action: Send an Email: To send an email notification that the User that triggered the Flow has checked-in at the site along with the Latitude, Longitude of the location from where the user checked-in.
Setup in Action
Flow run history for location tracking flow
In this article we saw how to create flows on-demand by creating template flows and then modifying certain trigger parameters on to them. This particular scenario corresponds to location tracking using the Geo Fence trigger and can be used for multiple LOB's like fleet management, logistics tracking and etc.
I hope you found this interesting and it helped you!