Hello Friends,
Welcome back with another post on Power Automate. We had already discussed about "Export To Excel" in our earlier posts. However, we are again going to discuss the same. This time, we are getting the data based upon the selection of View as well as filters applied in PowerApps. This post is also related to my previous two posts-
The final outcome of the flow is-
- Open the Power Automate maker portal and create a Instant cloud flow with trigger type as "PowerApps" and flow name as- "POC-DynamicExportToExcel".
- Now, we have 3 parameters to apply filter upon data-
- View Name
- Experience
- Free Text Search
- We will initialize 3 variables (using Initialize variable and value as Ask in PowerApps) that will communicate with PowerApps to provide these values to the flow-
- Variable1: ViewName
- Variable2: Experience
- Variable3: FreeTextSearch
- Now, we will define another variable named "strFilterCriteriaByViewName". This will be the first filter criteria.
- Keep saving your flow frequently.
- Here, we will use the same filter conditions as we applied in PowerApps. For that, we will apply a Switch-Case.
- Now, refer back to the previous post, where, we have defined the Views. Check the "Items" property of DataTable / Gallery.
- Please find below the function from PowerApps for ready reference.
Switch( Dropdown_SelectView.SelectedText.ViewName, "All Employees", Filter( EmployeeInfo, Experience.Value in If( Radio_SelectExperience.SelectedText.Experience = "All", Experience.Value, Radio_SelectExperience.SelectedText.Experience ) && (Trim(TextInput_Search.Text) in 'First Name' || Trim(TextInput_Search.Text) in 'Last Name' || Trim(TextInput_Search.Text) in Designation.Value || Trim(TextInput_Search.Text) in Experience.Value || Upper(Title) = Upper(Trim(TextInput_Search.Text))) || Text( 'Date Of Joining', "m/d/yyyy", "en-US" ) = Text( Trim(TextInput_Search.Text), "m/d/yyyy", "en-US" ) || Text(Trim(Salary)) = Trim(TextInput_Search.Text) ), "Software Engineer", Filter( EmployeeInfo, "Software Engineer" in Designation.Value, Experience.Value in If( Radio_SelectExperience.SelectedText.Experience = "All", Experience.Value, Radio_SelectExperience.SelectedText.Experience ) && (Trim(TextInput_Search.Text) in 'First Name' || Trim(TextInput_Search.Text) in 'Last Name' || Trim(TextInput_Search.Text) in Designation.Value || Trim(TextInput_Search.Text) in Experience.Value || Upper(Title) = Upper(Trim(TextInput_Search.Text))) || Text( 'Date Of Joining', "m/d/yyyy", "en-US" ) = Text( Trim(TextInput_Search.Text), "m/d/yyyy", "en-US" ) || Text(Trim(Salary)) = Trim(TextInput_Search.Text) ), "Module Lead", Filter( EmployeeInfo, "Module Lead" in Designation.Value, Experience.Value in If( Radio_SelectExperience.SelectedText.Experience = "All", Experience.Value, Radio_SelectExperience.SelectedText.Experience ) && (Trim(TextInput_Search.Text) in 'First Name' || Trim(TextInput_Search.Text) in 'Last Name' || Trim(TextInput_Search.Text) in Designation.Value || Trim(TextInput_Search.Text) in Experience.Value || Upper(Title) = Upper(Trim(TextInput_Search.Text))) || Text( 'Date Of Joining', "m/d/yyyy", "en-US" ) = Text( Trim(TextInput_Search.Text), "m/d/yyyy", "en-US" ) || Text(Trim(Salary)) = Trim(TextInput_Search.Text) ), "Project Manager", Filter( EmployeeInfo, "Project Manager" in Designation.Value, Experience.Value in If( Radio_SelectExperience.SelectedText.Experience = "All", Experience.Value, Radio_SelectExperience.SelectedText.Experience ) && (Trim(TextInput_Search.Text) in 'First Name' || Trim(TextInput_Search.Text) in 'Last Name' || Trim(TextInput_Search.Text) in Designation.Value || Trim(TextInput_Search.Text) in Experience.Value || Upper(Title) = Upper(Trim(TextInput_Search.Text))) || Text( 'Date Of Joining', "m/d/yyyy", "en-US" ) = Text( Trim(TextInput_Search.Text), "m/d/yyyy", "en-US" ) || Text(Trim(Salary)) = Trim(TextInput_Search.Text) ), "Program Manager", Filter( EmployeeInfo, "Program Manager" in Designation.Value, Experience.Value in If( Radio_SelectExperience.SelectedText.Experience = "All", Experience.Value, Radio_SelectExperience.SelectedText.Experience ) && (Trim(TextInput_Search.Text) in 'First Name' || Trim(TextInput_Search.Text) in 'Last Name' || Trim(TextInput_Search.Text) in Designation.Value || Trim(TextInput_Search.Text) in Experience.Value || Upper(Title) = Upper(Trim(TextInput_Search.Text))) || Text( 'Date Of Joining', "m/d/yyyy", "en-US" ) = Text( Trim(TextInput_Search.Text), "m/d/yyyy", "en-US" ) || Text(Trim(Salary)) = Trim(TextInput_Search.Text) ) )
- The same we are going to implement in flow. The primary filter is upon Designation-
- All Employees - No Filter Criteria
- Software Engineer - Filter Designation by "Software Engineer"
- Module Lead - Filter Designation by "Module Lead"
- Project Manager - Filter Designation by "Project Manager"
- Program Manager - Filter Designation by "Program Manager"
- We had completed first part.
- Now, we will fetch all such items from SharePoint list that matches this filter criteria. For that, we have to define three variables then use "Do Until" action to perform the activity.
- Now, we will use Do-Until action to fetch the items.
- Get Items Using ItemID variable & FilterCriteria
- Select the required fields
- Join the output with arrAllItems array
- Update the variable arrAllItems with the previous action result
- Update the intItemID with the last ItemID from the output of GetItems action. If GetItems action output is NULL, then assign it with 0.
- Now, check if the output of GetItems is empty or not. If empty, set the blnIsEmpty to true otherwise false.
- Now, we will set the "Configure Run After" condition for the action. For this, click on ellipses (3 dots) ahead to the Set blnIsEmpty action and choose "Configure run after".
- You will find that "is successful" is by default selected. Select "is failed" as well and click on Done.
- This completes the second part.
- Now, the third part is to filter data by Experience choice. If Experience selected by user is not "All", then we have to apply additional filter of Experience upon the outcome of Do-Until action.
- Before that, we will execute this flow and get the schema so that we can parse the output to JSON as we cannot apply filter upon array.
- Then use Parse JSON action.
- Now add a "Condition" action and check if Experience is not selected as "All". If true, apply "Filter" action on output of ParseJSON action and set the output again to arrAllItems variable.
- This completes third part.
- Now, the fourth part is to apply filter using free text search.
- This is the main section. Here we will apply filter on each field separately and capture the outcome in an individual array.
- After then we will combine all these outcomes in single array. Thus, unique results will be obtained.
- As we can see that we had applied free text search upon all 7 fields. Thus, we have to create 7 array variables and then apply filter one by one.
- First define the arrays.
- Now, check if the FreeTextSearch variable is having any value or not. If Yes, then start filtering one by one.
- Apply Parse JSON upon arrAllItems so that filter can be applied.
- We will check if the FreeTextSearch value is contained (unless specified) in the item respective field.
- Filter for Title field.
- Remember, when you are applying a filter, you have to use the output (body) of Parse JSON action. When you are updating the respective array with the output of respective filter, then you have to use the output (body) of Filter action.
- Filter for First Name field.
- Remember, when you are applying a filter, you have to use the output (body) of Parse JSON action. When you are updating the respective array with the output of respective filter, then you have to use the output (body) of Filter action.
- Filter for Last Name field.
- Remember, when you are applying a filter, you have to use the output (body) of Parse JSON action. When you are updating the respective array with the output of respective filter, then you have to use the output (body) of Filter action.
- Filter for Date Of Joining field. Here, we will first format the date to "M/d/yyyy" format and then check if both are equal. Additionally, here we will use the "Configure run after" as well because in case the FreeTextSearch is not a date then the formatDateTime will throw an error and our further processing will get failed. So, we have to handle that case.
- Remember, when you are applying a filter, you have to use the output (body) of Parse JSON action. When you are updating the respective array with the output of respective filter, then you have to use the output (body) of Filter action.
- Filter for Salary field.
- Remember, when you are applying a filter, you have to use the output (body) of Parse JSON action. When you are updating the respective array with the output of respective filter, then you have to use the output (body) of Filter action.
- Filter for Designation field.
- Remember, when you are applying a filter, you have to use the output (body) of Parse JSON action. When you are updating the respective array with the output of respective filter, then you have to use the output (body) of Filter action.
- Filter for Experience field. However, we can avoid filter condition upon Experience as this is already present upon screen in the form of Radio Choice.
- Remember, when you are applying a filter, you have to use the output (body) of Parse JSON action. When you are updating the respective array with the output of respective filter, then you have to use the output (body) of Filter action.
- Now, we have individual filter results for each FreeText filter criteria. We have to combine these outcomes. Thus, we will now use Compose action to apply union function to combine these outcomes. The benefit of union is that it takes unique items. If any item is found duplicate, it keeps only one of those item instances.
- Now, set the output of this Compose action to arrAllItems.
- This completes out fourth part.
- Now, the fifth & final part. Here, we will export this output to Excel. For this, you may refer my earlier blogs using OneDrive as well as SharePoint library.
- Using One Drive-
- Using SharePoint Library-
- This is how, we can Export data to excel.
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.
Stay Safe !
Stay Healthy !
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.