Advice on Split String [{},{}]

Hi everybody, I’m facing the follwing scenario:

  1. Im retrieving a queue item variable


2. I would like to split for each element on the {}

ID=175
AppName=Connect for Salesforce
Start_Date=08/31/2021
End_Date=09/01/2023
Quantity=1

ID=176
AppName=Connect 2.0 for Microsoft One
Start_Date=08/31/2021
End_Date=09/01/2023
Quantity=1

Thanks in advance for any advice

Cesar Cotom

Hi @Cesar_Cotom,

By looking at the queue item, it is clear that the disptacher has serialized a datatable into json string as value for in_Licenses key in your queue data.

There is a better way to get all of the key-value pairs in_Licenses in one go instead of getting ID, AppName, Start_Data, End_Date, Quantity separately. I assume here that the number of items in the json array (length of array) will be dynamic.

Approach

  1. Ensure you have the UiPath.Web.Activities package. This package allows you to parse xml and json strings by deseralizing them. In your dispatcher this same package has searialized a datatable into json string.

  2. Your queue item specific content is in_Licenses so use an Assign Activity and create a new DataTable variable LicensesDataTable
    LicensesDataTable= Newtonsoft.Json.JsonConvert.DeserializeObject(Of DataTable)(out_TransactionItem.SpecificContent("in_Licenses").ToString)

  3. Step two will output a datatable with the following structure

ID AppName Start_Date End_Date Quantity
175 Connect for Salesforce 08/31/2021 09/01/2023 1
176 Connect 2.0 for Microsoft One 08/31/2021 09/01/2023 1
  1. You can either use a For Each Row —> Row in LicensesDataTable and get values either in a for loop or if you fancy some linq queries you can use them.
    If you still want grab values from a datatable column then you can use
    LicensesDataTable.Rows(INDEX (integer)).Item("COLUMNNAME" (string)).ToString

    For example:
    First row (Index 0)
    LicensesDataTable.Rows(0).Item("AppName").ToString will return Connect for Salesforce

    Second row (Index 1)
    LicensesDataTable.Rows(1).Item("Start_Date").ToString will return 08/31/2021

    You get the drill here :slight_smile:

There are no performance issues in this method so you should be fine processing in_Licenses containing upto 5000 rows (if necessary). If the row count reaches higher than this a linq query is far superior in terms of execution time.

You can refer to similar question in a solved thread here : Adding data table into queue - Help / Activities - UiPath Community Forum

Hope this helps you clear your doubts.

2 Likes

Hi @jeevith , thank you very much for your help and sharing your knowledge

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