web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to get a sub-item ...
Power Automate
Answered

How to get a sub-item of an array?

(0) ShareShare
ReportReport
Posted on by 2,297

My array looks like this:

 

[
 {
 "@odata.etag": "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=\"",
 "planId": "johCFoq4nEyhOcbgjLkzN5YAFYWU",
 "bucketId": "uoRC3WMr70WkaUCOGWZ69JYAJEHv",
 "title": "Reception, validation and account of local suppliers invoices",
 "orderHint": "8585975908743310360",
 "assigneePriority": "",
 "percentComplete": 0,
 "createdDateTime": "2020-10-30T00:00:11.1465447Z",
 "dueDateTime": "2020-10-30T07:00:10Z",
 "hasDescription": false,
 "previewType": "automatic",
 "referenceCount": 0,
 "checklistItemCount": 0,
 "activeChecklistItemCount": 0,
 "id": "vd9Lt6swoU6yUsBenCKW9ZYAFmAE",
 "createdBy": {
 "user": {
 "id": "25e6bf64-416e-45c2-8350-9f747027d3c5"
 }
 },
 "appliedCategories": {},
 "assignments": {
 "9c950320-9981-45a3-b31e-2cd31d69d51a": {
 "@odata.type": "#microsoft.graph.plannerAssignment",
 "assignedDateTime": "2020-10-30T00:00:11.1465447Z",
 "orderHint": "8585975909344403874Pg",
 "assignedBy": {
 "user": {
 "displayName": null,
 "id": "25e6bf64-416e-45c2-8350-9f747027d3c5"
 }
 }
 }
 },

 

In order to get the title, the following expression works well:

 

items('Apply_to_each')?['title']

 

But I want the user whose taks was assigned to. So, in the JSON this is under the "assignements" element, as a sub-element of the main object. Thus:

 

items('Apply_to_each')?['assignements']

 

Returns an empty string.

 

Categories:
I have the same question (0)
  • sudharsan1985 Profile Picture
    1,325 on at

    Hi @WebPortal 

    Try the below options. In your sample JSON, there is no assigned to so I tried to use the assigned by property

    1. items('Apply_to_each')?['assignements/assignedby']
    
    2. items('Apply_to_each')?['assignements/assignedby/user/id']
    
    3. items('Apply_to_each')?['assignements']?['assignedby']
    
    4. items('Apply_to_each')?['assignements']?['assignedby']?['user']?['id']

    Try it out and let me know

     

  • WebPortal Profile Picture
    2,297 on at

    @sudharsan1985 maybe you misunderstood my question.

     

    I'm not looking for the "assigned by", ie, the person who assigned the task.

     

    I'm looking for the assignee, ie, the person responsible to perform the task. 

     

    So, I think it is this part of the JSON what I need:

     

    "assignments": {
     "9c950320-9981-45a3-b31e-2cd31d69d51a": {
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @WebPortal ,

     

    if the JSON expression that you provided at the end of your post is what you have in your flow, the reason that you're returning an empty string might be that you misspelled "assignments" by adding an "e" between the "n" and "m" and that i think you need to add an underscore (_) to the front of it like this:

     

    items('Apply_to_each')?['_assignments']

    JSON can be tricky

    I hope this helps.

     

    thanks,

    Kyle

  • WebPortal Profile Picture
    2,297 on at

    @Anonymous thanks,

     

    That is returning everything under "assignments". 

     

    All I need is:

    9c950320-9981-45a3-b31e-2cd31d69d51a

    (And then, for another post, how to translate that into the user email and name.)

     

    Thanks for your help!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @WebPortal 

     

    OK, so it looks like since the assignee value can be it's own array (multiple assignees) you have to loop through all "assignments" even if there's only one.

     

    a trick to troubleshooting the JSON is to use Dynamic Content provided by Power Automate and then look at the syntax by hovering your cursor over the Dynamic Content.

     

    so basically, within your loop that's iterating through the tasks, you need another apply to each loop to go through the "assignments" pulling out the userId of the assignee(s):

    PlannerTaskAssignee.png

     

    You can then use the get user data action block, pass in the User ID, and get their email address:

     

    GetUserProfile.png

     

    Let me know how it goes!

     

    Kyle

     

     

     

     

  • WebPortal Profile Picture
    2,297 on at

    @Anonymous  thank you for helping.

     

    I've tried a lot of stuff, but I can't make it. Now, I'm getting the error:

     

    The execution of template action 'Apply_to_each_2' failed: the result of the evaluation of 'foreach' expression '@items('Apply_to_each')' is of type 'Object'. The result must be a valid array.

     

    WebPortal_0-1604701330985.png

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @WebPortal ,

     

    It looks like you're going through an extra step of putting the Task details into an array since the task details already return as an array. If your first "Apply to Each" loop iterates through the output of "get tasks", you'll get the same array as the screenshot in your first post above.

     

    also, for your second loop, rather than looping through "current item" you should be looping through "assignments", from there you can pull the "assignments user ID" for however you need to use it.

  • Paulie78 Profile Picture
    8,422 Moderator on at

    @WebPortal this would be my approach. You need to replace variables('someArray') with your actual output (or create a variable called someArray with the content of your output:

    GetElement.PNG

     

    The second compose gives this output:

    composeOutput.PNG

     

    Code for the first compose:

     

    substring(string(variables('someArray')[0]['assignments']),2)

     

    Code for the second compose:

     

    substring(outputs('Compose'), 0, indexOf(outputs('Compose'), '"'))

     

    It can all be done in a single compose easily. But I thought it would be more readable in this form.

     

    Explanation

    Your output is an array, but presumably it has only one value. So I accessed the first element of the array and then the assignments property of it. Which gets you down to just this:

     

    {
    	"9c950320-9981-45a3-b31e-2cd31d69d51a": {
    		"assignedDateTime": "2020-10-30T00:00:11.1465447Z",
    		"orderHint": "8585975909344403874Pg",
    		"assignedBy": {
    			"user": {
    				"displayName": null,
    				"id": "25e6bf64-416e-45c2-8350-9f747027d3c5"
    			}
    		}
    	}
    }

     

    Then the first compose turns the output into a string, and collects everything except the first two characters. Which leaves you with this:

     

    9c950320-9981-45a3-b31e-2cd31d69d51a":{"assignedDateTime":"2020-10-30T00:00:11.1465447Z","orderHint":"8585975909344403874Pg","assignedBy":{"user":{"displayName":null,"id":"25e6bf64-416e-45c2-8350-9f747027d3c5"}}}}

     

    The second compose gets a substring of the first compose and stops when it finds the first double quotation mark. Which leaves you with this:

     

    9c950320-9981-45a3-b31e-2cd31d69d51a

     

    Try it and see how you get on.

  • WebPortal Profile Picture
    2,297 on at

    @Anonymousthank you for your help.

     

    also, for your second loop, rather than looping through "current item" you should be looping through "assignments", from there you can pull the "assignments user ID" for however you need to use it.


    That sure makses sense... But WHERE can I find the option to loop through assignments?

     

    Captura de ecrã 2020-11-11 102156.jpg

  • WebPortal Profile Picture
    2,297 on at

    @Paulie78 

     

    It's almost working.

     

    The array "Tarefas" in my flow contains multiple elements.

     

    For every element, the output 2 is always:

     

    9c950320-9981-45a3-b31e-2cd31d69d51a

     

    So, I guess the 1st compose is not working well.

     

    This is how it all looks like now:

     

    WebPortal_0-1605098938601.png

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 484

#2
Valantis Profile Picture

Valantis 477

#3
Haque Profile Picture

Haque 456

Last 30 days Overall leaderboard