Skip to main content

Notifications

Power Automate - Building Flows
Suggested answer

Iterating through users, getting list of cities

(0) ShareShare
ReportReport
Posted on by
Hey people,
 
I tried chatGPT, I tried Copilot, I tried videos, I tried Google searches, but I can't find any answer (and I assume it should be quite simple).
I want to create a list for my Sharepoint. A list from all 'cities' in the personal information of all users - bonus if cities can be made unique and not show up 100 times.
This is what I have so far (already sorry that it's german):
My thoughts:
-> Trigger (manually for now, no idea how to trigger it)
-> initialize variable (array) empty
-> search for users V2
-> loop through all users
   -> "Select" from previous 'value', map: 'City' value: item()?['city']
   -> "add to array" (City) (output from Select)
-> Create List
 
Last one, creating an element/list is my biggest issue, I have no options to select any output from the previous loop and I don't get why. I have the option to directly select City ('Ort') from the previous 'Search for users' which makes me wonder if I think too complicated or if Power Automate is smart enough to automatically generate an array if I just completely ignore the whole loop inbetween? Also I have no idea how to test it.
 
Thanks in advance :)
  • Suggested answer
    David_MA Profile Picture
    David_MA 8,929 on at
    Iterating through users, getting list of cities
    You can use the Graph API call to get the cities: https://graph.microsoft.com/v1.0/users?$select=city. You can test this using the Graph API Explorer at Graph Explorer | Try Microsoft Graph APIs - Microsoft Graph as you'll need the necessary permissions in Entra ID to make the call.

    Then in your flow, you can use a Union expression on the array to remove duplicate values: (union(variables('YourArray'), variables('YourArray'))
     
    However, you will have one major challenge if your company has more than 1,000 users. When you need to return more than 1,000 rows, you need to implement paging to return all of the values. You can learn about that at Paging Microsoft Graph data in your app - Microsoft Graph | Microsoft Learn. If you get this far, you may need to submit another post, as I have only done this one time and am by no means an expert in implementing this step.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,445

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,741

Leaderboard