Hello Friends.
Welcome back with another post on Power Automate. Have you ever tried to sort an array in Power Automate. Yes, Sorting. You surprised because, there is no direct function or action provided in Power Automate to sort an array. Well, today, we will look for work around for the same.
Here, we will use an array of emails and will try to sort alphabetically. Let's start.
- I am using an Instant cloud flow with trigger as "Manually trigger a flow".
- Define an array "arrayUnsortedEmails".
- Now, we need 4 variables-
- arrayFilteredEmails- It will be used to hold the filtered emails every time our loop completes one round .
- arraySortedEmails- It will be used to hold the final sorted array of emails and will be assigned at the end of flow.
- strSmallestEmail- It will be used to hold an email id which will be compared with the emails residing in arrayFilteredEmails and if any email is smaller than this value then the variable will update it's value with the new one.
- intRowsCount- It will be used to hold the total number of emails captured in arrayUnsortedEmails array.
- intRowIndex- it is a counter variable which will be used for loop execution.
- Let's continue and initialize all the above variables.
- Now, we will use a Do-until loop where, we will-
- Extract the first email from arrayFilteredEmails.
- Apply a loop on arrayFilterEmails and check if any other email is smaller (alphabetically sort) than the first email. If Yes, then update the strSmallestEmail with the new email and continue the verification.
- Once Apply to each loop ends, add the value of strSmallestEmail into arraySortedEmails.
- Filter the arrayFilteredEmails and exclude this smallest email.
- Assign the output to arrayFilteredEmail.
- Increment the intRowIndex with 1.
- The Do-until loop continues the same process again and again till index reaches to the count.
- Once the Do-until execution completes, we will get the sorted array.
- Now, if you wish to see the output, you may assign the output to a new array variable.
- Let's define an array named "arrayFinalOutput" and assign it the value of arraySortedEmails.
- All done. Save the flow and test it.
- I will show you the initial array and the final array.
- Initial Array-
- Final Array-
- Let me show you the data in notepad-
- This way you can implement sorting upon arrays in Power Automate.
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.