cancel
Showing results for 
Search instead for 
Did you mean: 

Combining Collections by code, works in VS not in BP.

ThomasWarnaar
Level 4
Hi all,

I have to merge two collections horizontally (So add the columns of collection x to the right of the columns of collection y). I wrote some code for this which works fine in Visual Studio but gives me problems in Blue Prism.
I get the message that there is no conversion possible from collection to text. 

The code in BP is as follows (appendDt is the collection to append, mainDt is the collection to append to, collOut is the merged output collection):
--------------------------------------------------------------------------------------------------
sErrorMsg = "";
bError = false;

try
{
for (int i = 0; i < appendDt.Columns.Count; i++)
{
mainDt.Columns.Add(appendDt.Columns.ColumnName.ToString(), appendDt.Columns.DataType);
}
for (int i = 0; i < mainDt.Rows.Count; i++)
{
for (int j = 0; j < appendDt.Columns.Count; j++)
{
mainDt.Rows[appendDt.Columns[j].ColumnName.ToString()] = appendDt.Rows[j];
}
}

}
catch (Exception ex)
{
sErrorMsg = ex.Message;
bError = true;
}

collOut = mainDt;
--------------------------------------------------------------------------------------------

Further investigation in BP using MessageBox.Show between each line of code shows me that the problem arrises in the first "for" statement. I suspect BP's code engine does not recognize the COLLECTION.Columns.Count property but tries to find a field called Columns.Count in the input Collection/DataTable. 

What can I do?



------------------------------
Thomas Warnaar
------------------------------
1 BEST ANSWER

Best Answers

IsmoLehtiniemi
Level 5
Isn't the "Merge Collection" -action from Blue Prism's native Utility - Collection Manipulation -object doing exactly what you want to achieve?

------------------------------
Ismo Lehtiniemi
RPA Architect & Solution Expert
Amcor
Europe/Warsaw
------------------------------

View answer in original post

3 REPLIES 3

AndreyKudinov
Level 10
1) I'd remove try/catch to check exception.
2) You might hit a case where column with that name exists in original collection
3) I'd use foreach (probably not important)
4) Collection manipulation either had that action or I made my own, nevertheless code in VB:

For Each c As DataColumn in c2.Columns
	c1.Columns.Add(c.ColumnName, c.DataType)
Next

For r As Integer = 0 To c1.Rows.Count - 1
	If r < c2.Rows.Count Then
		For Each c As DataColumn in c2.Columns
			c1.Rows(r)(c.ColumnName) = c2.Rows(r)(c.ColumnName)
		Next
	Else
		Exit For
	End If
Next

c3 = c1​


------------------------------
Andrey Kudinov
Project Manager
MobileTelesystems PJSC
Europe/Moscow
------------------------------

IsmoLehtiniemi
Level 5
Isn't the "Merge Collection" -action from Blue Prism's native Utility - Collection Manipulation -object doing exactly what you want to achieve?

------------------------------
Ismo Lehtiniemi
RPA Architect & Solution Expert
Amcor
Europe/Warsaw
------------------------------

@IsmoLehtiniemi Yeah indeed! I think I missed that because when I tried that one I made it cast the merged collection to one of the original collections, which didn't work because the field definitions don't match.

Now I tried casting it to a new colelction and it works as it should. Thanks!​

------------------------------
Thomas Warnaar
------------------------------