Adding dictionary to queue and retrieve dictionary from queue

is there any way i can add a dictionary to a queueitem (the dictionary may have different number of values for each queueitem)?

then when retrieiving transaction item, retrieve back the dictionary and do our own splitting?

1 Like

Yes, you can use the Item Collection property.

Activities - Add Queue Item -

Hi @TyraS

The following thread contains the required data:

Hope this helps,
Best Regards.

Hi @TyraS

Can you follow the below steps

  1. Create a Queue variable to store the dictionaries. Let’s call it queueData . You can define this variable in the Variables panel or by using the Assign activity with the following
new Queue(Of Dictionary(Of String, Object))()

This creates an empty queue that can store dictionaries with string keys and object values.

  1. Create a dictionary that you want to add to the queue. Let’s call it dictData. Populate it with the desired key-value pairs.

  2. To add the dictionary to the queue, use the Add To Collection activity. Configure the activity as follows:

  • Collection : queueData
  • Item : dictData
  • CollectionType : System.Collections.Generic.Queue<System.Collections.Generic.Dictionary<System.String,System.Object>>

This adds the dictionary to the queue.

  1. U se the Assign activity to assign the dequeued item to a variable. Let’s call it retrievedDict . Use the following expression:
retrievedDict = queueData.Dequeue()
  1. You can now use the retrieved dictionary (retrievedDict ) in subsequent activities.
Assign activity : queueData = new Queue(Of Dictionary(Of String, Object))()

Assign activity:
   dictData = new Dictionary(Of String, Object)()
   dictData.Add("Key1", "Value1")
   dictData.Add("Key2", 123)

Add To Collection activity:
   Collection: queueData
   Item: dictData
   CollectionType: System.Collections.Generic.Queue(Of System.Collections.Generic.Dictionary(Of String, Object))

Assign activity:
   retrievedDict = queueData.Dequeue()

Message Box activity:
   "Retrieved Dictionary : " + retrievedDict("Key1").ToString() + ", " + retrievedDict("Key2").ToString()


Hi, is it adding to queue in orchestrator?
Each time will only add 1 dictionary though, will we still need the Add to Collection?

sry is a little confusing

I think what you meant is,
you have a queue item with different specific contents, like name, address, age, and one of those specific content is dictionary itself, like, I don’t know favourite recipes, so your queue item would be like name,address,age,recipes:

I have a solution, but I was looking around if there is a better one, that’s how I got to this post.
So far what I have solution looks fine. So here I share:

So you have a dictionary:

Assign dict=
New Dictionary(Of String, String) From {
{“scrambled egg”, “stir the egg, then fry the egg”},
{“pizza”,“roll the dough, put toppings, bake it”}

Then you serialize it
Assign dictSTR = Newtonsoft.Json.JsonConvert.SerializeObject(dict)

Basically it converts to a Json format (that is a String), and that can be converted back easily, so you gonna get something like:
dictSTR=“{{"scrambled egg", "stir the egg, then fry the egg"}, {"pizza","roll the dough, put toppings, bake it"}}”

(ignore the wrong quotation marks, there’ll be escaped in the conversion)

This is a string now, so I don’t need to explain how you can add it into a queue item easily (as SpecificContent) just can be used as name, or address, or age.

To convert it back it’s even easier, you don’t need to write code, there is a Deserialize activity
you just need to set like 3 properties,

JsonString: dictSTR
TypeArgument to: System.Collection.Generic.Dictionary<System.String, System.String>
JsonObject: yourResultDictionary

Have fun!