cancel
Showing results for 
Search instead for 
Did you mean: 

Collection inside a collection

DennisLaursen
Level 4
I am using a REST/JSON functionality to export data to collections. But sometimes I get a collection inside a collection, and I am in doubt how to "extract" these collections. Is there a way to extract collections from collections, eventually with the "Utility - Collection Manipulation"?
15 REPLIES 15

RAJENJAFUJIYAMA
Level 2
We can actually refer to the items like so: [collectionName.items.FieldName]. We can have a collection to contain multiple layers of collections, but the way to refer to any layer would be the same.

------------------------------
RAJENJA FUJIYAMA
------------------------------

Hi,

You can store the sub-collection data into another Collection stage by using 'Append Rows To Collection' action, In order to access the sub collection, you can use the following expression: [Parent Collection.Sub-Collection]

Also, please note that if you try to directly access any sub collection field from the looping pointer being set at the parent collection stage like, [Parent Collection.Sub Collection.Field1], then in that case by default the value of the first row of Sub collection for Field1 column will be fetched. If you want to access any other row data for that sub collection then you either need to again iterate through that sub collection or you can use the action 'Get Collection Field' which will accept a row index and the field name. You can pass any index from 0 to N-1 if N rows are available and it should be able to give you the values.

------------------------------
Regards,
Devneet Mohanty
Intelligent Automation Consultant
Blueprism 6x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com
------------------------------
----------------------------------
Hope it helps you out and if my solution resolves your query, then please provide a big thumbs up so that the others members in the community having similar problem statement can track the answer easily in future.

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Technical Business Analyst,
WonderBotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------

Hi Dennis, I am facing a similar situation , if you could please elaborate more on how it worked for you ? The steps that you followed please .

Thanks in Advance !



------------------------------
SHaikh
------------------------------

Hi Shaikh,

You can try to follow the below steps:

Suppose you have the collections as below:

The Collection which has another collection in it say OuterColl and the collection inside is known as InnerColl:

Defination:
20790.png

20792.png

Current Values:

20793.png

20794.png

Create an empty collection say UnallocatedColl

and then use the below Calculation Stage:

20795.png

Once you run this the InnerColl details will be copied to UnallocatedColl:

20796.png

Now you can work as needed.



------------------------------
Manish Rawat
Project Manager
Mercer
New Delhi
------------------------------

Thank you for your solution Manish!

But the problem that I am facing is , the inner collection has a single row and every field in the inner collection is a collection. These fields change everytime and are large in number .

I used the Action: Get Collection Fields to get the inner collection fields in a different collection .

But I am not getting how to loop on the field names collection and inner collection , to get every collection in the inner collection separately in a temp collection .

Thanks,

Nusrat



------------------------------
SHaikh
------------------------------

Hi Shaikh,

You can achieve that by creating a custom action in the collection manipulation utility with below parameters:

Input:

Collection

Columnname

RowNumber:

Output:

found

ValueText

ValueCollection

Error

Code Stage snippet below:

valueColl = New DataTable()
valueText = ""
errorMessage = ""
found = False

Try

    If coll.Columns.Count = 0 Then
        
        'No columns present in Collection
        errorMessage = "The collection does not contain any columns."

    ElseIf String.IsNullOrEmpty(colname) Then
        
        'Empty column is provided
        errorMessage = "Provided column name is empty."
    
    ElseIf Not coll.Columns.Contains(colname) Then
        
        'Column not present in the provided collection
        errorMessage = "The collection does not contain a field with the name "&colname
    
    ElseIf coll.Rows.Count < rownumber Or rownumber<=0 Then
        
        'Provided row is not presnet in the collection
        errorMessage = "The collection does not contain row number "&rownumber

    Else
    
        ' Initialise output params
        
        Dim DataType As String = GetBluePrismDataType(coll.Columns(colname).DataType)

        If DataType.ToLower().Trim() = "collection" Then
            valueColl = CType(coll.Rows(rownumber-1).Item(colname), DataTable)
            found = True
        Else
            valueText = coll.Rows(rownumber-1).Item(colname).ToString()
            found = True
        End If

    End If

Catch ex As Exception
    ' Catch any exceptions thrown and set found to false
    found = False
    errorMessage = ex.Message
End Try

The below code will give output in ValueColl if the provided columname is Collection and if the same is other than this it will provide you the text value

CAUTION: If the field is of type password then you will get the text value of the password itself

Hope that was helpful.



------------------------------
Manish Rawat
Project Manager
Mercer
New Delhi
------------------------------