How to Add a Dictionary to a List in Studio X

I am trying to build a list of Dictionary’s based off of emails

I set a Dictionary value like this New Dictionary(Of String, String) from {{“Sender”, CurrentEmail.Sender}, {“Subject”, CurrentMail.Subject}, {“Date”, CurrentMail.Date}}.
That is working

When I loop through the dictionary it prints the values fine using Message Box so I know the right values are being set.

Now I am trying to figure out how to Append that Dictionary to a List. And Everything I try just errors out

I only have access to Studio X presently, as that is all my company will approve of

HI,

Can you try as the following?

dict = New Dictionary(Of String, String)
listDict = New List(Of Dictionary(Of String,String))()

Then use ApeendItemToList activity

image

Sample
Main.xaml (4.9 KB)

Regards,

That doesn’t work I get this error

Hi,

Can you share type of EmailList variable? It should be List<Dictionary<string,string>>

Regards,

  1. Create a List of Dictionaries:
  • First, you need to initialize a list to store the dictionaries. This can be done using the Assign activity:

MyList = New List(Of Dictionary(Of String, String))()


Where `MyList` is a variable of type `List(Of Dictionary(Of String, String))`.
2. **Create a Dictionary:**
  * In the process where you're fetching email data, create the dictionary for each email, as you already did:


New Dictionary(Of String, String) From {{"Sender", CurrentMail.Sender}, {"Subject", CurrentMail.Subject}, {"Date", CurrentMail.Date}}
  1. Append Dictionary to List:
  • Use the Add to Collection activity to append the dictionary to your list:
    • Set the Collection to your list variable (MyList).
    • Set the Item to your dictionary (which contains the email data).
    • Ensure that the TypeArgument is set to Dictionary(Of String, String).
  1. Loop Through Emails:
  • Inside the loop where you iterate through emails, you can repeat the above steps to append each email’s dictionary to the list.

This method allows you to append the dictionary without modifying the original list or encountering errors.

hovering over it says
System.Collections.Generics.List<System.Collections.Generic.Dictionary<System.String, System.String>>

I don’t see an Add to Collections, or Append Items to Collection activity in Studio X. All I see is Append Item to List

Hi,

Can you also check if TypeArgument property of AppendItemToList is Dictionary<String,String> ?

Regards,

Hey Thank you. I think that solved the issue. The Properties tab is harder to see in Studio X than it is in Studio

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.