How to upload entire DataTable as single queue item || UiPath

Pradumn Kumar
3 min readNov 20, 2022

--

You might come across projects where you have multiple data tables to be processed. The requirement would be to upload each such datatable as individual queue item.

In this blog, you will learn how to do that with a complicated use-case made easy!

How to upload DataTable as a queue item in UiPath

Problem Statement

Refer to below input file snapshot. You need to upload each P.O. group as single queue item. (Eg: Row 2–6 is a group[1 queue item])

Snapshot of Input File. Each PO

Solution

On high level, these should be the sequence of steps you need to take:

  • Read entire sheet as data table
  • Group rows by P.O. Number
  • Iterate through each group
  • Store each group as datatable
  • Serialize this datatable into JSON string
  • Upload JSON string as queue

Now let's look at how to implement it in UiPath

Steps: Read entire sheet as data table; Group rows by P.O. Number
Steps: Iterate through each group and store as datatable; Serialize this datatable and upload.

Step 1: Use Read Range activity to read the Sheet1 of “InputFile.xlsx” into a variable named dt_InputData of type System.Data.DataTable.

Step 2: Use Assign activity to group rows according to the P.O. number. The result can be assigned to a variable named POGroup of type IEnumerable <IGrouping(Object,DataRow)> as shown below:

Variable Type of POGroup
POGroup = dt_InputData.AsEnumerable.GroupBy(Function(x) x.Item("P.O. Number"))

Step 3: Use For Each loop to iterate through this POGroup variable and store each group in variable named POLineItems. The type of argument should be IGrouping<Object,DataRow>

Step 3a: Use Assign activity to store POLineItems in a datatable variable named dt_POLineItems.

dt_POLineItems = POLineItems.CopyToDataTable

Step 3b: Use Assign activity to convert dt_POLineItems into JSON string variable named SerializedObj.

SerializedObj = JsonConvert.SerializeObject(dt_POLineItems)

NOTE: If you don’t see above JSONConvert.SerializeObject method, you will need to import Newtonsoft.JSON namespace from the imports panel.

Step 3c: Use Add Queue Item activity to upload SerializedObj into queue named TestQueue (You need to create a queue if not already done). Below is the snap of the Item Information tab of the actvity:

Snapshot of the Item Information tab of the Add Queue Item activity

Result Check

Now check the TestQueue details from orchestrator. It should contain 4 new items for the respective PO Groups:

The individual transaction would like this:

Voila! It’s done! You have successfully uploaded each PO group as individual queue item!!

Extra dose

You can always use below steps to convert the JSON string back to DataTable after you get the transaction item for processing:

How to convert JSON string back into datatable
JsonConvert.DeserializeObject(Of DataTable)(TransactionItem.SpecificContent("LineItemsCollection").ToString)

Feel free to Follow me for more such easy-to-understand content. I am also available on LinkedIn :-)

Thank you for your time!! See you soon.

--

--

Pradumn Kumar

Hey there! I’m a software professional with 5+ yrs of overall experience. I’ve deep interest in tech and geopolitics, which lures me deep into these topics.