cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
WillPage
Impactful Individual
Impactful Individual

Flattening an object

I'm trying to create an item in a SharePoint list using some data from the Microsoft Graph API. The data comes like this in the code block below. I used the Parse JSON data operation to create the dynamic content, and obvioulsy assignedLicenses is an object. It can contain nothing, or several skuIds (no limit I guess). I don't care about disabledPlans, which is an object itself.

 

{
    "value": [
        {
            "displayName": "Megan Bowen",
            "userPrincipalName": "MeganB@M365x214355.onmicrosoft.com",
            "assignedLicenses": [
                {
                    "disabledPlans": [],
                    "skuId": "f30db892-07e9-47e9-837c-80727f46fd3d"
                },
                {
                    "disabledPlans": [],
                    "skuId": "18181a46-0d4e-45cd-891e-60aabd171b4e"
                }
            ]
        }
    ]
}

I have no problem creating the SharePoint list item, with displayName and userPrincipalName, but I need to know how to handle the assignedLicenses object.

 

I know I can remove the "type": object from the schema and make the whole thing a text string, which gets the skuIds into the SP list, but also all the other text, which is messy and hard to work with.

 

I tried to create a CSV table with assignedLicenses property as the input and one column on the output, skuId. It runs OK but this is the output (using the example above as the input):

f30db892-07e9-47e9-837c-80727f46fd3d
f30db892-07e9-47e9-837c-80727f46fd3d

The first skuId is repeated twice. The number of assignedLicenses is always correctly represented by the number of rows in the table (3 assignedLicenses, 3 rows etc), but those rows are always a repeat of the first. I'm not sure if I'm doing it wrong or the CSV Table operation is buggy/broken.

 

I feel like I need something like the Concat() function in PowerApps but I don't know how to do it. Help please!

2 ACCEPTED SOLUTIONS

Accepted Solutions
v-bacao-msft
Community Support
Community Support

Hi @WillPage ,

 

You could extract skuId and form a new array, the array element is object, only contains a property-skuId.

 

  1. Initialize an array variable, then use Parse JSON action to parse Value and extract the required parts.
  2. Traverse the assignedLicenses and append the value of skuId to each element in the array.
  3. Finally, the variable is used as the source for creating CSV table.

 

Image reference:

67.PNG

68.PNG69.PNG

 

Run history:70.PNG

 

Please take a try.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

WillPage
Impactful Individual
Impactful Individual

@v-bacao-msftThanks for your reply. I can see how this would work, but I get weird results

Capture.PNG

Apologies for the low res picture but I think it's clear enough. The outer loop is going around value, like in your example (there are 78 of those), then the inner loop is going around assignedLicenses. In this screen shot, despite there being 2 records in the assignedLicenses object, the inputs are clearly there, but the CSV table is empty.

 

In some others of the 78 records, I have the opposite problem, a CSV table is being created with nothing being appended to the array. The last action of the outer loop, after SharePoint Create Item, is Set Variable assignedLicenses-skuId Value null to empty the variable ready for the next item in the loop.

 

Capture.PNG

In other instances, assignedLicenses has some values and the loop goes round appending the array variable, but the CSV table outside of the inner loop contains completey different rows to what I would expect.

 

I moved this to a Logic app now, but I don't think the actions are any different than Flow.

View solution in original post

4 REPLIES 4
v-bacao-msft
Community Support
Community Support

Hi @WillPage ,

 

You could extract skuId and form a new array, the array element is object, only contains a property-skuId.

 

  1. Initialize an array variable, then use Parse JSON action to parse Value and extract the required parts.
  2. Traverse the assignedLicenses and append the value of skuId to each element in the array.
  3. Finally, the variable is used as the source for creating CSV table.

 

Image reference:

67.PNG

68.PNG69.PNG

 

Run history:70.PNG

 

Please take a try.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

WillPage
Impactful Individual
Impactful Individual

@v-bacao-msftThanks for your reply. I can see how this would work, but I get weird results

Capture.PNG

Apologies for the low res picture but I think it's clear enough. The outer loop is going around value, like in your example (there are 78 of those), then the inner loop is going around assignedLicenses. In this screen shot, despite there being 2 records in the assignedLicenses object, the inputs are clearly there, but the CSV table is empty.

 

In some others of the 78 records, I have the opposite problem, a CSV table is being created with nothing being appended to the array. The last action of the outer loop, after SharePoint Create Item, is Set Variable assignedLicenses-skuId Value null to empty the variable ready for the next item in the loop.

 

Capture.PNG

In other instances, assignedLicenses has some values and the loop goes round appending the array variable, but the CSV table outside of the inner loop contains completey different rows to what I would expect.

 

I moved this to a Logic app now, but I don't think the actions are any different than Flow.

View solution in original post

WillPage
Impactful Individual
Impactful Individual

Figured this out - concurrency control in the for-each loop. Set to 1 it works perfectly. Thanks for the help.

Hi @WillPage ,

 

Create CSV table action is not included in Apply to each, it is not in the loop.

 

Image reference:73.PNG

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,319)