Update Value in Dictionary KeyValuePair

Question: How do I update the value of a kevaluepair inside a dictionary?

Details:

I have a dictionary called out_Config defined as Dictionary<String,Dictionary<String,Object>> That is the output of UiPath.Web.Activities.DeserializationJson.

out_Config is populated by deserializing a JSON string that looks like

{
“GlobalAssets”:{
“SMTPFromEmailAddress” : “SMTPFromEmailAddress”,
“SMTPPort” : “SMTPPort”,
“SMTPServer” : “SMTPServer”,
},
“ProcessAssets”:
{
“DataConnectionUrl”:“DataConnectionUrl”,
“eMailRecipient”:“DataConnection_eMailRecipient”,
“logF_BusinessProcessName”:“DataConnectionUserManagement”,
},
}

So the GlobalAssets node is a dictionary of keyvaluepairs accessible by out_Config(“GlobalAssets”).

What I am trying to do is loop through the out_Config(“GlobalAssets”) dictionary to get the asset value of each keyvaluepair stored in Orchestrator and then update the value in the dictionary. The get asset activity is successful.

My current implementation of out_Config(“GlobalAssets”).Item(item.Key) in the assign activity is throwing the error “For Each: Collection was modified; enumeration operation may not execute.” I think this is because I am updating the key and not the value.

What should I put in the left side of the assign activity to update the value of the key?

You cannot enumerate through a Collection and modify it at the same time.

What you can try to do is enumerate through the Dictionary’s Keys and modify the Dictionary using its keys

Here’s a working example:

Dictionary.xaml (6.8 KB)

1 Like

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