Create dictionary from QueueItem string

Hello -

I have a string (strTestJSON) that is generated from the output of a ‘Get Transaction Item’ activity using TransactionItem.SpecificContent(“TestContent”).ToString

QueueItem { AssignedTo=null, DeferDate=null, DueDate=null, Id=486110, ItemKey=[56891ee6-1fcb-4402-976a-ea4eacd400cd], LastProcessingOn=null, Output=null, Priority=Normal, ProcessingException=null, Progress=“”, QueueDefinitionId=576, QueueName=“InterimTestData”, Reference=“16798”, RetryNo=0, ReviewStatus=“None”, RowVersion=byte[8] { 0, 0, 0, 0, 0, 15, 175, 102 }, SpecificContent=Dictionary<string, object>(9) { { “TestID”, “16798” }, { “OwnRef”, “automation-test-69421378” }, { “PreviouslyFailed”, “False” }, { “FailedStep”, “” }, { “DefectList”, “” }, { “TestContent”, @"{
““id””: "“1"”,
““test_id””: ““16798"”,
““status_id””: null,
““created_on””: null,
““assignedto_id””: null,
““comment””: ““Report on run for test 16798:””,
““version””: null,
““elapsed””: ““1m 0s””,
““defects””: null,
““created_by””: null,
““custom_step_results””: [
> {
> ““actual””: “” \n - Log in check successfully completed\n - Log in authenticated\n - Bank App loaded successfully"",
> ““status_id””: "“1"”,
> ““content””: ““Instruction: Log on to Bank App and navigate to Manual Transaction module””,
> ““additional_info””: ““Elapsed: 00h 00m 48s””
> },
> {
> ““actual””: “” \n - Template code selected successfully\n - Template details correctly filled in\n - Payment created successfully"",
> ““status_id””: "“1"”,
> ““content””: ““Instruction: Select payment template and enter details””,
> ““additional_info””: ““Elapsed: 00h 01m 04s””
> },
> {
> ““actual””: “” \n - Payment removed from Manual Transaction screen and added to Payment Recon\n - Payment successfully accepted"",
> ““status_id””: "“1"”,
> ““content””: ““Instruction: Accept the now created payment””,
> ““additional_info””: ““Elapsed: 00h 00m 10s””
> }
> ]
> }” }, { “Attachments”, “System.String” }, { “EvidenceLocation”, “C:\Users\xxxx\xxxxx\UiPath\temp\UiPath Tests\FormatsTest.evidence\16798” }, { “CanDo”, true } }, StartTransactionTime=[08/08/2022 04:22:13], Status=InProgress }

I am trying to turn the bold content into the following Dictionary<String, String>

Dictionary<string, string>(4) { { “actual”, string[3] { " \n - Log in check successfully completed\n - Log in authenticated\n - Bank App loaded successfully", " \n - Template code selected successfully\n - Template details correctly filled in\n - Payment created successfully", " \n - Payment removed from ‘Manual Transaction’ screen and added to ‘Payment Factory’\n - Payment successfully accepted" } }, { “status_id”, string[3] { “1”, “1”, “1” } }, { “content”, string[3] { “Instruction: Log on to Bank App and navigate to Manual Transactions module”, “Instruction: Select payment template and enter details”, “Instruction: Accept the now created payment” } }, { “additional_info”, string[3] { “Elapsed: 00h 00m 48s”, “Elapsed: 00h 01m 04s”, “Elapsed: 00h 00m 10s” } } }

Does anyone have any recommendations?

Thanks in advance.

Regards,
symilawr

there are some doubts when looking to the string sample in combination with the info:

the doubts comes from following:


it looks more like a QueueItem Object visualisation with its properties (e.g. from some debugging panels) So we do have properties …
Would it be a fully JSON string then we would expect that e.g. AssignedTo is surrounded with a " etc

When focussing on the bold part which is the value from
YourQueueItem.SpecificContent(“custom_step_results”) containing a JObject with a property: custom_step_results having JArray as value. the JArray has multiple JObjects.

As a Dictionary needs to have unique keys an option would be to parse it within a JArray or to deserialize it within a list(Of Dictionary(of String, String)

As a starter try to Deserialize the value of YourQueueItem.SpecificContent(“custom_step_results”).toString into a JObject and postprocess the result

Maybe you can share some more details (screenshots, xaml) from your implementation. Thanks

Also have a look here:


JSONConvert.DeserializeObject(Of List(Of Dictionary(Of String, String)))(myJObject("custom_step_results").toString)

Hi ppr -

Thanks for the quick reply.

Sorry for the confusion - below is the JSON string (strTestJSON)

@“{
““id””: ““1"”,
““test_id””: ““16798"”,
““status_id””: null,
““created_on””: null,
““assignedto_id””: null,
““comment””: ““Report on run for test 16798:””,
““version””: null,
““elapsed””: ““1m 0s””,
““defects””: null,
““created_by””: null,
““custom_step_results””: [
{
““actual””: “” \n - Log in check successfully completed\n - Log in authenticated\n - Bank App loaded successfully””,
““status_id””: ““1"”,
““content””: ““Instruction: Log on to Bank App and navigate to Manual Transaction module””,
““additional_info””: ““Elapsed: 00h 00m 29s””
},
{
““actual””: “” \n - Template code selected successfully\n - Template details correctly filled in\n - Payment created successfully””,
““status_id””: ““1"”,
““content””: ““Instruction: Select payment template and enter details””,
““additional_info””: ““Elapsed: 00h 01m 01s””
},
{
““actual””: “” \n - Payment removed from Manual Transaction screen and added to Payment Factory\n - Payment successfully accepted”",
““status_id””: ““1"”,
““content””: ““Instruction: Accept the now created payment””,
““additional_info””: ““Elapsed: 00h 00m 10s””
}
]
}”

Here is the deserialized value (jobjDeserializedTestJSON)

JObject(11) { JProperty(1) { [1] }, JProperty(1) { [16798] }, JProperty(1) { }, JProperty(1) { }, JProperty(1) { }, JProperty(1) { [Report on run for test 16798:] }, JProperty(1) { }, JProperty(1) { [1m 0s] }, JProperty(1) { }, JProperty(1) { }, JProperty(1) { JArray(3) { JObject(4) { JProperty(1) { [

  • Log in check successfully completed
  • Log in authenticated
  • Bank App loaded successfully] }, JProperty(1) { [1] }, JProperty(1) { [Instruction: Log on to Bank App and navigate to Manual Transaction module] }, JProperty(1) { [Elapsed: 00h 00m 29s] } }, JObject(4) { JProperty(1) { [
  • Template code selected successfully
  • Template details correctly filled in
  • Payment created successfully] }, JProperty(1) { [1] }, JProperty(1) { [Instruction: Select payment template and enter details] }, JProperty(1) { [Elapsed: 00h 01m 01s] } }, JObject(4) { JProperty(1) { [
  • Payment removed from Manual Transaction screen and added to Payment Factory
  • Payment successfully accepted] }, JProperty(1) { [1] }, JProperty(1) { [Instruction: Accept the now created payment] }, JProperty(1) { [Elapsed: 00h 00m 10s] } } } } }

The code you posted appears to get me a lot closer to where I need to be. I will test it and let you know what I get!

Thanks for the help.

symilawr

@ppr -

The code you provided gets me closer to where I need to be.

Essentially, I am needing to concatenate all of the values after the keys {“actual”, “status_id”, “content”, “additional_info”}. For example, rather than having these three sections of data split out:

““actual””: “” \n - Log in check successfully completed\n - Log in authenticated\n - Bank App loaded successfully""
““actual””: “” \n - Template code selected successfully\n - Template details correctly filled in\n - Payment created successfully""
““actual””: “” \n - Payment removed from Manual Transaction screen and added to Payment Factory\n - Payment successfully accepted""

I would have 1 key value pair (Of string, array of string) like below:

Dictionary<string, string>(4) { { “actual”, string[3] { " \n - Log in check successfully completed\n - Log in authenticated\n - Bank App loaded successfully", " \n - Template code selected successfully\n - Template details correctly filled in\n - Payment created successfully", " \n - Payment removed from ‘Manual Transaction’ screen and added to ‘Payment Factory’\n - Payment successfully accepted" } }

Thanks again for the help.

symilawr

There are many options to implement it.

Continuing with dictList strategy from above we can do:

Variables:

Flow
grafik

dictList = JSONConvert.DeserializeObject(Of List(Of Dictionary(Of String, String)))(myJObject("custom_step_results").toString)
dictLK = 
(From k In dictList(0).Keys
Let arrVal = dictList.Select(Function (d) d(k)).toArray
Select t = Tuple.Create(k,arrVal)).ToDictionary(Function (x) x.Item1, Function (x) x.Item2)

Many thanks ppr!

That worked. I really appreciate your help.

Regards,
symilawr

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