HI,
I am trying to read from a Dictionary output provided by the box connected system as shown below . How to read each items such as ID and type to a local variable ?
I tried fn!index(local!folderContents,"id") but it is giving me null output
Please help me
Discussion posts and replies are publicly visible
Hi Ramanan,
This looks to be a list of dictionary from the screenshot. Did you explore using the same index() function within the forEach() loop? That could probably give you what you want.
HI Nishant, I tried putting for loop but it is still giving me null
Your dictionary is nested to a few levels, so you can't access the "id" property just from the top.
The easiest way to figure this out is do it one step at a time.
First write local!folderContents.result to access entries; then to access a specific entry you can write local!folderContents.result.entries[1]; finally you can access the id property within the specific entry by expanding that to local!folderContents.result.entries[1].id. Finally, if you really want the id field within "file_version", you will need to reach one level further down.
The index() and property() functions are useful for doing null-safe indexing, but when you're sure of the shape of the data you'll get, you can access the properties and indexes directly as written above.
solution suggested by mike will work but i would suggest first get this in some variable
index(index(local!folderContents,"result",{})"entries",{})
then run the code in a!foreach loop and get the id.
You can use index() function twice to get the entries (i.e. 2 dataset). Post that you can have a!forEach through which you can extract fv!item.id.
For your reference:
a!forEach(
items: index( index( local!folderContents,"result",{}), "entries",{}),
expression: fv!item.id
)
In the interest of acknowledging the elephant in the room, is it entirely possible to simply NOT NEST the dictionary? Could you refactor the dictionary such that it's not nested? It looks like this is 4 Dictionaries deep.
Two questions really worth considering on a deep, deep level.
1. Why is it nested? What do you gain from the multiple levels? I venture that you gain nothing but the massive headache you're dealing with right now. There's no reason all the fields from all the nested parts of "entry" can't just be on the top level of "entry", and there's no reason for the "entry" list to be nested inside two more levels of dictionary either. What does "result" add that makes it indispensable? Nesting is generally not recommended, and nesting more than 2 or 3 levels deep is a violation of Appian best practices, so why start the precedent now?
2. Why are you using Dictionary? Why aren't you using a CDT? Dictionaries are great for an ad hoc replacement for CDT structure that isn't finalized yet. It's great for mock-ups, but when you do finalize the data's structure, you're supposed to replace it with a CDT. The CDT is more manageable and makes sure that the structure is maintained, and helps you index fields better, because it comes with a guarantee that those fields are actually there. With a list of Dictionary, each one in the list could have any fields. Nothing guarantees the structure will be what you expect.