cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Collection saving fields as objects

I think I may have titled this wrong, but I'm unsure on how to discribe it in one sentence. I created a custom connector to get data from an API. Here is a portion of my response if get when making the request:

[
    {
        "purchaseDate": "string",
        "serialNumber": "string",
        "version": null,
        "location": {
            "id": int,
            "type": "string",
            "address": "string",
            "city": "string",
            "locationName": "string",
            "postalCode": "string",
            "state": "string",
            "defaultPriorityTypeId": null
        }
   }
]

So far so good. When I paste my default response into my custom connector creator, is shows all of my variables returned:

Capture.PNG

 

Everything looks great. Notice it doesn't show "location", but shows all of the variables returned within "location" such as "location type" or "location id". They all show up when trying to access with Microsoft Flow:

 

Capture.PNG

 

Here's where my problem starts. When I put the returned data into a Collection in PowerApps, I can only access "location", not any of the variables within it. The collection stores "location" as "object Object". This happens with any data that is nested within a root variable such as "location":

 

Capture.PNG

 

I need to diplay information such as "location locationName" or other nested variables, but the Collection will not store them. Is there something I am missing here? If this is not possible in PowerApps, how can I get the data into PowerApps?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Collection saving fields as objects

When you import the connector to Flow, it "flattens" the objects so that all of the primitive values (strings, numbers, etc.) are exposed directly. In PowerApps the response is interpreted "as is", so you need to access it via the object hierarchy.

 

If you want to expose the data in a gallery, then you can edit the formula for the items directly. For example, if you create a connector for the example you have, you can save the response in a collection:

ClearCollect(coll, MyCustomAPI.GetData())

And on the gallery, set the Items property to the collection (coll). Now, you can add labels to the gallery template and set its properties to:

Label1.Text: "Purchase date: " & ThisItem.purchaseDate
Label2.Text: "Serial: " & ThisItem.serialNumber
Label3.Text: "Address: & ThisItem.location.address & ", " &
        ThisItem.location.city & ", " &
        ThisItem.location.state & ", " &
        ThisItem.location.postalCode

If you want to use the data in a control that needs the primitive types (such as a data table), then you can modify the collection to "flatten" the items that you want. For example, instead of saving the result of the API directly in the collection, you can use the AddColumns function to extract some of the nested properties:

ClearCollect(
    coll,
    AddColumns(
        MyCustomAPI.GetData(),
        "location_address", location.address,
        "location_city", location.city,
        "location_state", location.state,
        "location_postalCode", location.postalCode))

And you'll then see those properties show up in the data table customization pane.

4 REPLIES 4
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Collection saving fields as objects

When you import the connector to Flow, it "flattens" the objects so that all of the primitive values (strings, numbers, etc.) are exposed directly. In PowerApps the response is interpreted "as is", so you need to access it via the object hierarchy.

 

If you want to expose the data in a gallery, then you can edit the formula for the items directly. For example, if you create a connector for the example you have, you can save the response in a collection:

ClearCollect(coll, MyCustomAPI.GetData())

And on the gallery, set the Items property to the collection (coll). Now, you can add labels to the gallery template and set its properties to:

Label1.Text: "Purchase date: " & ThisItem.purchaseDate
Label2.Text: "Serial: " & ThisItem.serialNumber
Label3.Text: "Address: & ThisItem.location.address & ", " &
        ThisItem.location.city & ", " &
        ThisItem.location.state & ", " &
        ThisItem.location.postalCode

If you want to use the data in a control that needs the primitive types (such as a data table), then you can modify the collection to "flatten" the items that you want. For example, instead of saving the result of the API directly in the collection, you can use the AddColumns function to extract some of the nested properties:

ClearCollect(
    coll,
    AddColumns(
        MyCustomAPI.GetData(),
        "location_address", location.address,
        "location_city", location.city,
        "location_state", location.state,
        "location_postalCode", location.postalCode))

And you'll then see those properties show up in the data table customization pane.

Anonymous
Not applicable

Re: Collection saving fields as objects

Perfect! This is exactly what I needed. Thank you!

eag768
Level: Powered On

Re: Collection saving fields as objects

You are literally my saviour today!

Super User
Super User

Re: Collection saving fields as objects

Hi @CarlosFigueira . Do you have pointers for handling nested JSON at 3-4 levels deep? I'm seriously stuck on this right now.

Thank you