cancel
Showing results for 
Search instead for 
Did you mean: 

static collection

AnushaGP
Level 3

how to  Use Code stage to copy data to static collection. Pass Input as Collection schema, if not passed then code will create own collection else write data to input collection.



------------------------------
Anusha GP
------------------------------
5 REPLIES 5

ewilson
Staff
Staff
Hello @AnushaGP,

I'm not sure I understand your question, but one important thing to understand here is that a Blue Prism Collection is just a .NET DataTable behind the scenes. So anything you can do with a DataTable, you can do with a Collection in a Code stage.

Back to your question, are you talking about passing a Collection into a Code stage that has defined columns but may not have any rows?

Cheers,

------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

I need a code to copy data into static collection

------------------------------
Anusha GP
------------------------------

@AnushaGP,

Ok. As I said previously, a Blue Prism Collection is nothing more than a .NET DataTable within a Code stage. There are lots of examples online for dealing with DataTables. In fact, you could take the Utility - Collections Manipulation VBO and review the Code stages it contains as they all implement different bits of code for dealing with a Collection/DataTable. 

If what you're looking for is the code the create a Collection from scratch in a Code stage, it looks something like this (of course the DataColumn definitions would change based on your specific use case).

' Create new DataTable instance.
Dim table As New DataTable

' Create 3 typed columns in the DataTable.
table.Columns.Add("FName", GetType(String))
table.Columns.Add("LName", GetType(String))
table.Columns.Add("Email", GetType(String))

' Add a few rows with those columns filled in the DataTable.
table.Rows.Add("John", "Doe", "jdoe@email.com")
table.Rows.Add("Robert", "Johnson", "rj@blahblah.com")
table.Rows.Add("Philip", "Masters", "pmasters@junkmail.com")

' Set our Output data item (i.e. Collection) to the value of the new DataTable
myCollection = table

Cheers,

------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

@ewilson  Do you know what the datatable implementation looks like in the background when you have a collection within a collection? A column in a datatable can only be value types, if im not mistaken?



------------------------------
Ivar Buvarp Toft
RPA Develop
Europe/Oslo
------------------------------

@Ivar Buvarp Toft 

Here's an example:

// Create the top-level/parent DataTable and define a DataColumn of type DataTable.
DataTable cars = new DataTable();
cars.Columns.Add("Name", typeof(string));
cars.Columns.Add("Specs", typeof(DataTable));

// Define the child DataTable
DataTable carSpecs = new DataTable();
carSpecs.Columns.Add("VIN", typeof(string));
carSpecs.Columns.Add("Model Year", typeof(int));
carSpecs.Columns.Add("Color", typeof(string));

// Populate the child DataTable
carSpecs.Rows.Add("123456789", 1990, "Red");
carSpecs.Rows.Add("987654321", 1965, "White");
carSpecs.Rows.Add("741258963", 2005, "Black");

// Insert the child DataTable into the parent. 
cars.Rows.Add("Mustang", carSpecs);


You can take this idea pretty much as deep as you want to go. Just remember that if you want to drill into the values within a child DataTable, you have to make sure to cast the value of the cell containing the child to type DataTable.

Cheers,
 



------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------