How to put in "Dictionary" in "Dictionary"?

Hello.
I wanna ask a question here.

Now I’m trying to make a dictionary data that contains of dictionary data.
That’s actually like this.

《Dictionary(Of String, Dictionary(Of String, Object))》

Is it possible?
I cannnot find the activity “AddToDictionary” now.
So I’m trying to use “AddToCollection” instead.

I would be glad to know it…
Thank you and Best regards,

Yes, it is possible and your syntax is correct, although I would stop and think why a setup like this is needed as it might be overcomplicating things.

AddToDictionary should be in Workflow Manager Activities package IIRC.

Thank you very much for your quick response.
Could I ask you a little bit more?

Now I’m using “AddToCollection” activity for it.
Collection(Left): Dictionary(of String, Dictionary(of String Object))
Item(right): Dictionary(of String, Dictionary(of String Object))

If you were me, what kind of TypeArgument of AddToDictionary do you specify?

I tried many kind type of, But didin’t work at all. (caused errors)

Thank you and Best regards,

That’s why I said it can get overcomplicated :wink:
But if using it as actual dictionaries and not collections, it gets a little easier.
Sample attached below.
When adding using AddToDictionary use actual types:
So if your “main” dictionary is Dictionary(of String, Dictionary(of String, Object)) then your TKey is String and your TValue is Dictionary(Of String, Object), because that’s what they are.
For your “nested” dictionary Dictionary(Of String, Object) it is easier and your TKey is String (again) and your TValue is Object.

Remember to initialize them before usage to not get null reference exceptions :wink:

If you have more nesting levels (that’s really a moment to stop and rethink), just wrap the type declaration in another level. Example (broken to multiline for easier viewing, all are keyed by Strings):

Dictionary(Of String,
   Dictionary(Of String,
       Dictionary(Of String,
           Dictionary(Of String, Object)
       )
    )
)
// or in one line
Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, Dictionary(Of String, Object))))

For getting/setting values directly to nested, you can use:

// set
mainDictionary(mainDictKeyAsString)(nestedDictKeyAsString) = yourValueAsObject;
// get
object myValue = mainDictionary(mainDictKeyAsString)(nestedDictKeyAsString);
// get a DateTime
DateTime myDateTime = CDate(mainDictionary(mainDictKeyAsString)(nestedDictKeyAsString));
// etc.

Just remember that you can chain key indexers as many times as needed, although I’d really not recommend going above 2 nesting levels and build a proper object structure as a custom package if you need to go above as it will be unusable for anyone but you (and you’ll still have easy errors to do).

Sequence.xaml (6.9 KB)

1 Like

Thank you very much for your kindly support!!
Actually It didn’t work with using complicated Nest as you’re saying.

But I found an other way and made it.

I really appericiate your advise.
I got new things.

Thank you and Best regards,

what is the other way ? can u please explain it will be usefull to others!