How to fetch data from nested CDTs data

A Score Level 1

I have a nested CDT which contains the response from a service.

I want to fetch the data from nested levels.

'type!{urn:com:appian:types}testCDT'(
  id: null,
  response: 'type!{urn:com:appian:types}response'(
    users: {
      'type!{urn:com:appian:types}users'(
        userId: "12345",
        groupId: "2342",
        addresses: 'type!{urn:com:appian:types}userAddress'(
          type: "test",
          street: "New",
          addressLines: { "a", "b" },
          countryCode: "980",
          postalCode: "6456"
        )
      ),
      'type!{urn:com:appian:types}users'(
        userId: "2568",
        groupId: "8995",
        addresses: 'type!{urn:com:appian:types}userAddress'(
          type: "NEw test",
          street: "Old",
          addressLines: { "c", "d" },
          countryCode: "589",
          postalCode: "2546"
        )
      )
    }
  )
)

I am trying to fetch the addressLines data due to multi level, I am not able to fetch the data.

Is there any other way to get the data?

  Discussion posts and replies are publicly visible

  • Hi Ram,

    There are few different ways how you could retrieve the data that you are looking for, but in most cases, you will end up using a looping function.

    If you just want a plain list of the address lines, not considering the address type, you could try a code like the below one, or you could adjust it to your needs.

    a!localVariables(
      local!test: 'type!{urn:com:appian:types}testCDT'(
        id: null,
        response: 'type!{urn:com:appian:types}response'(
          users: {
            'type!{urn:com:appian:types}users'(
              userId: "12345",
              groupId: "2342",
              addresses: 'type!{urn:com:appian:types}userAddress'(
                type: "test",
                street: "New",
                addressLines: { "a", "b" },
                countryCode: "980",
                postalCode: "6456"
              )
            ),
            'type!{urn:com:appian:types}users'(
              userId: "2568",
              groupId: "8995",
              addresses: 'type!{urn:com:appian:types}userAddress'(
                type: "NEw test",
                street: "Old",
                addressLines: { "c", "d" },
                countryCode: "589",
                postalCode: "2546"
              )
            )
          }
        )
      ),
      local!b:  a!flatten(a!forEach(
        items:      index(index(local!test.response,"users",null),"addresses",null),
          expression: fv!item.addressLines
        )
        ),
        local!b
      )
    

    There was other topics discussing similar situation, you can check the link below for example:

    Only fields with scalar types can be indexed from an array

    Regards,

    Acacio Barrado