cancel
Showing results for 
Search instead for 
Did you mean: 

Convert the collection rows into column

Miya
Level 5
Hi,

  I have a collection which actually i got when i got a table in email in HTML format and converted into plain text, currently the collection has only 1 row eg
Current format
row1
row 2
row 3
row 4
A
b
c
d
1
2
3
4
Expected format
row 1     row2   row 3 row4
A              b           c           d
1              2           3          4

basically the data's in single row collection has to be split into different columns 

Thank You

------------------------------
Miya
------------------------------
6 REPLIES 6

LucasSilva
Level 4
Hello Miya,

You can use the 'Transpose Vector Into Collection' action of the Collection manipulation utility.
If you don't have access to the utility I put a link to it at the end.

To use this action, just pass your collection that has only one column and then pass a collection containing only the columns you want to form.

24981.png
24982.png
24984.png
24986.png
https://digitalexchange.blueprism.com/dx/entry/3439/solution/utility---collection-manipulation

Hope this helps, if you still have any questions let me know.

------------------------------
Lucas Silva
------------------------------

Hi,

   I am not able to get the transpose vector into collection action after importing the object from the link you provided, can you double check the link, because when i open the document attached to the utility collection manipulation it shows only transpose action,i am npt able to see the transpose vector into collection or is this object has version compatibility iam using bp v 6.8

------------------------------
Miya
------------------------------

You can create a new action within this utility that I sent in the previous answer, which has this option.

For that, you must create a new page inside the utility and add the following code blocks.

Input
25000.png


Code

25001.png
Output

25002.png
Inside the code block

Input

25003.png
Code

25004.png
Code to paste:

If ((collection.Rows.Count Mod columns.Columns.Count) <> 0) Then
Throw New ApplicationException("The supplied collection doesn't have the right size")
End If
If ((collection.Columns.Count) <> 1) Then
Throw New ApplicationException("The supplied collection doesn't have the right size")
End If

result = New DataTable()
For Each c As DataColumn in columns.Columns
result.Columns.Add(c.ColumnName, c.DataType)
Next

dim j as integer = 0
Dim newRow As DataRow

For c As Integer = 0 To collection.Rows.Count - 1
if (j Mod result.Columns.Count = 0) then
j = 0
newRow = result.NewRow()
end if

if(c < result.Columns.Count) then
newRow(c) = collection.Rows(c)(0)
else
j = c Mod result.Columns.Count
newRow(j) = collection.Rows(c)(0)
end if
if (j Mod result.Columns.Count = 0) then
result.Rows.Add(newRow)
end if
j = j + 1
Next

When finalizing and checking the code, if an error appears, check that on your Initialise Page there are all the necessary libraries as shown below:

1)
25005.png
2)
25006.png

#BPTechTips

------------------------------
Lucas Silva
RPA Developer
------------------------------

Hi Lucas,

I am trying your code right now but received this code error. I've checked the Initialise page libraries and there is nothing wrong there, exactly the same as yours. Any idea how to resolve? 25022.png



------------------------------
Nafiz Zainal
------------------------------

Hi Nafiz, 

result must be declared as an output parameter of your codestage. Have you done that?

Best, 

Michael



------------------------------
Michael Wulf
Senior Developer Robotic Process Automation
e.kundenservice NETZ GmbH
Europe/Hamburg
------------------------------

Hi,

I got the data from Notepad into Collections but it came in one row. Now, I want to have this data into different columns.

Division#  Contract#/     Name              Address Type  Change Field     Address-Old ? all this came in one single column in a Collection, I want them in separate columns.

Please help me how to do it.



------------------------------
Mohammed Abdul Shakeel
------------------------------