I suppose it depends on the content, and how you want to combine.
Are the columns the same? If so, Utility - Collection Manipulation has an action called Append Rows to Collection. If the columns are different, you could instead use the Merge Collection action. If you're looking for something more like a join statement, here's a C# stage that'll do a Left Outer Join.
Inputs:
Left Collection - Collection
Right Collection - Collection
Key Field - Text
Outputs:
Collection Out - Collection
if(!Left_Collection.Columns.Contains(Key_Field))
throw new Exception("Left Collection does not contain key field '" + Key_Field + "'.");
else if(!Right_Collection.Columns.Contains(Key_Field))
throw new Exception("Right Collection does not contain key field '" + Key_Field + "'.");
DataTable temp = new DataTable();
foreach(DataColumn Column in Left_Collection.Columns)
{
temp.Columns.Add(Column.ColumnName, Column.DataType);
}
foreach(DataColumn Column in Right_Collection.Columns)
{
if(Column.ColumnName == Key_Field)
{
}
else if(temp.Columns.Contains(Column.ColumnName))
{
throw new Exception("Collections contain non-key duplicate field ('" + Column.ColumnName + "').");
}
else
temp.Columns.Add(Column.ColumnName, Column.DataType);
}
foreach(DataRow OuterRow in Left_Collection.Rows)
{
DataRow[] MatchingRows = Right_Collection.Select("[" + Key_Field + "] = '" + OuterRow[Key_Field] + "'");
if(MatchingRows.Length > 0)
{
foreach(DataRow Match in MatchingRows)
{
DataRow New_Row = temp.NewRow();
foreach(DataColumn dColumn in Left_Collection.Columns)
{
New_Row[dColumn.ColumnName] = OuterRow[dColumn.ColumnName];
}
foreach(DataColumn dColumn in Right_Collection.Columns)
{
New_Row[dColumn.ColumnName] = Match[dColumn.ColumnName];
}
temp.Rows.Add(New_Row);
}
}
else
{
DataRow New_Row = temp.NewRow();
foreach(DataColumn dColumn in Left_Collection.Columns)
{
New_Row[dColumn.ColumnName] = OuterRow[dColumn.ColumnName];
}
temp.Rows.Add(New_Row);
}
}
Collection_Out = temp;
On the other hand, if you're looking to add a column to an existing collection of type Collection, this stage may interest you.
Inputs:
Collection - Collection
colName - Text
colType - Text
Outputs:
New Collection - Collection
DataColumn col = new DataColumn();
if(colType=="Number"){
col.DataType = System.Type.GetType("System.Int32");}
else if(colType=="Text" || colType=="Password"){
col.DataType = System.Type.GetType("System.String");}
else if(colType=="Collection"){
col.DataType = typeof(DataTable);}
else if(colType=="Date" || colType=="DateTime" ||colType=="Time"){
col.DataType = System.Type.GetType("System.DateTime");}
else if(colType=="Flag"){
col.DataType = System.Type.GetType("System.Boolean");}
else if(colType=="TimeSpan"){
col.DataType = System.Type.GetType("System.TimeSpan");}
else if(colType=="Image"){
col.DataType = typeof(Bitmap);}
else if(colType=="Binary"){
col.DataType = System.Type.GetType("System.Byte[]");}
col.ColumnName = colName;
Collection.Columns.Add(col);
New_Collection = Collection;
------------------------------
Ami Barrett
Lead RPA Software Developer
Solai & Cameron
America/Chicago
------------------------------
Original Message:
Sent: 09-10-2019 12:12
From: Jonathan Holstine
Subject: Combining Collections
I have two collections that I need combined and added to a queue. What is the best approach to do this?
1) Combine the collections into one new collection and then add to queue? If so does someone have an example or guidance on this?
2) Is there a way to add to queue without first combining into a new collection?
Thanks!
------------------------------
Jonathan Holstine
Systems Accountant
Interior Business Center
America/Denver
------------------------------