cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MallonoX
Frequent Visitor

Creating an Array per User from MS Graph

Hey Everyone,

 

I'm pretty far down the road with a Flow to query the graph api for user delta changes. I just need to pass the JSON body to a Desktop Flow.

 

The output after a Parse JSON looks like this:

 

 

 

 

 

{
    "from": [
        {
            "jobTitle": "Retail Manager",
            "companyName": "Testing",
            "department": "Testing",
            "userPrincipalName": "AdeleV@y37.onmicrosoft.com",
            "country": "United States",
            "id": "152a2f01-2de6-4030-8b23-da0fafe2"
        },
        {
            "jobTitle": "Marketing Assistant",
            "companyName": "Testing",
            "department": "Testing",
            "userPrincipalName": "AlexW@y37.onmicrosoft.com",
            "country": "United States",
            "id": "ec31b4cd-b3b7-4e4b-89a8-c94921d"
        },
        {
            "department": "Testing",
            "userPrincipalName": "testadmin@y37.onmicrosoft.com",
            "id": "e3fe7172-7c9a-4463-9176-b0006c17b"
        },
        {
            "jobTitle": "HR Manager",
            "department": "Testing",
            "userPrincipalName": "DiegoS@y37.onmicrosoft.com",
            "country": "United States",
            "id": "db9b2dd7-7295-409a-a3d9-ade02982"
        },
        {
            "jobTitle": "Designer",
            "department": "Testing",
            "userPrincipalName": "GradyA@y37.onmicrosoft.com",
            "country": "United States",
            "id": "20836cc9-3bdf-445a-9d63-ce304b7c"
        }
    ]
}

 

 

 

 

 

 

And the Desktop Flow looks like this:

Screenshot 2022-06-17 174408.png

(the AddToGroup flow is just a test for a PowerShell script)

The mapping of the Desktop flow variables is easy. What I can't figure out is the For Each "user" component. What do I use to group the values by user? The best I've been able to get so far is an ungrouped array of values.

 

Cheers.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-yujincui-msft
Community Support
Community Support

Hi @MallonoX ,

 

Maybe you could try to write the expressions manually.

 

body('Parse_JSON_-_Users')?['from']
 
items('Apply_to_each')
 
vyujincuimsft_1-1655797300408.png

Result Screenshot:

vyujincuimsft_2-1655797375344.png

 

 

 

Best Regards,
Charlie Choi

View solution in original post

4 REPLIES 4
v-yujincui-msft
Community Support
Community Support

Hi @MallonoX ,

 

Do you want to get an object once by once?

 

I have made a test for your reference.

vyujincuimsft_0-1655789299905.png

vyujincuimsft_1-1655789544465.png

Result Screenshot:

vyujincuimsft_2-1655789648414.png

If you want to get the value of a field, you can select the corresponding dynamic content.

vyujincuimsft_3-1655789808058.png

Result Screenshot:

vyujincuimsft_4-1655789874835.png

In addition, I recommend that you hide your private information, such as using fictitious field values.

 

 

Best Regards,
Charlie Choi

MallonoX
Frequent Visitor

Hey @v-yujincui-msft 

 

That's awesome! The first example is exactly what I'm after; where each loop contains a "set" of attributes.

 

What are the expressions you used for 'from' and 'item'? I don't have either in the Dynamic Content list. Although I'm guessing 'from' is the Body of the preceding Parse JSON?

I think whatever the expression is for 'item' is what I've been searching for.

 

Cheers.

 

Screenshot 2022-06-21 163504.png

 

 

v-yujincui-msft
Community Support
Community Support

Hi @MallonoX ,

 

Maybe you could try to write the expressions manually.

 

body('Parse_JSON_-_Users')?['from']
 
items('Apply_to_each')
 
vyujincuimsft_1-1655797300408.png

Result Screenshot:

vyujincuimsft_2-1655797375344.png

 

 

 

Best Regards,
Charlie Choi

MallonoX
Frequent Visitor

Hey @v-yujincui-msft 

 

You're a legend! That didn't work specifically because I realized the example Parse JSON I posted in my initial post was from a different Graph query and the "from" field wasn't there, which is why I didn't see it in the Dynamic Content expressions. But applying the same logic worked a treat. 😁

 

This is the expression that worked for me: 

body('Parse_JSON_-_Users')?['value']

 

What I've now realized was causing the problem is the "automatic" Dynamic Content expression for "value" is:

body('Parse_JSON_-_Users')?[body]?['value']

 

Screenshot 2022-06-22 105314.png

 

For future reference I had to make custom expressions for each of the variables in the desktop flow, e.g.:

outputs('Compose')['department']
outputs('Compose')['id']
outputs('Compose')['jobTitle']
 
Cheers.

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (5,078)