Merge 2 collections on a condition to populate a nested collection - blueprism

I have 2 collections in which I get data from DB.
Collection 1 column names: A_id, Bid, PCid, Bname ==> all text fields
Collection 2 column names: A_ref, Cid, Cname, value ==> all text fields
Collection 1 and 2 are related based on collection1.A_id=collection2.A_ref
I have a 3rd collection which is a nested collection:
Collection 3 Column names: action(text), colA (collection)
colA column names: Bid(text), PCid(text), Bname(text), colB (collection)
colB column names: Cid, Cname, value ==> all text fields
I want to join collection 1 and collection 2 based on mentioned condition to load the nested collection 3.
Please help.
I have tried using the collection VBO but didnt succeed. I also tried using a nested loop stage and counters with a decision stage but my code fails to add empty row to the nested collection before populating the values.
Using Blueprism stages
I want to join collection 1 and collection 2 based on mentioned condition to load the nested collection 3.
I am using a nested loop stage and counters with a decision stage but my code fails to add row to the nested collection.

Aswin, please check the solution below:
For further information, i will pass the XML file as for you to import to Blue Prism and check every stage, since it would require a lot of time and screenshots to explain everything. Plus you will have a clear understanding of every step in your environment.
Download XML file from my github repository link:
Blue Prism Merge Collections to populate a nested-collection
Hope these information will be useful.

I believe what you're looking for is what I call a "box join". You'll need a code stage.
Inputs:
Main (collection)
Nested (collection)
Main Key (text)
Nested Key (text)
New Field Name (text)
Outputs:
Output Collection
Code:
' Check for requirements: key columns exist, and that the new field to create in the main
' collection does not already exist.
If Not Main.Columns.Contains(Main_Key) Then
Throw New Exception("Main Collection does not contain the key column '" & Main_Key & "'")
Else If Not Nested.Columns.Contains(Nested_Key) Then
Throw New Exception("Nested Collection does not contain the key column '" & Nested_Key & "'")
Else If Main.Columns.Contains(New_Field_Name) Then
Throw New Exception("Main Collection already contains a field named '" & New_Field_Name & "'")
End If
' Add the column containing the DataTable which will be populated with data from the Nested collection.
Main.Columns.Add(New_Field_Name, GetType(DataTable))
For Each MainRow As DataRow In Main.Rows
' Create the new nested table for this row and populate the column names.
Dim Table As New DataTable
For Each NestedColumn As DataColumn In Nested.Columns
Table.Columns.Add(NestedColumn.ColumnName, NestedColumn.DataType)
Next
' Because we don't want to copy the key column.
Table.Columns.Remove(Nested_Key)
' Check each row in the Nested collection to see if it matches current key.
For Each NestedRow As DataRow In Nested.Rows
If MainRow(Main_Key) = NestedRow(Nested_Key) Then
' Got a match; add the row from Nested into the new table.
Dim NewRow As DataRow = Table.NewRow
For Each TableColumn As DataColumn In Table.Columns
NewRow(TableColumn.ColumnName) = NestedRow(TableColumn.ColumnName)
Next
Table.Rows.Add(NewRow)
End If
Next
' Set the nested collection
MainRow(New_Field_Name) = Table
Next
Output_Collection = Main
Using the example from the question, you'll want to pass the following into the code stage inputs:
[Collection 1] -> Main
[Collection 2] -> Nested
"A_id" -> Main Key
"A_ref" -> Nested Key
"colB" -> New Field Name
The resulting Output Collection will contain the fields from Collection 1, with an added column "colB" which contains the fields (excluding the key) from Collection 2. From there, a calculate stage can get the results into Collection 3.

Related

Is there a vbo to get value from a collection based on value of other fields and save it as a data item?

Relatively new to Blue Prism,
I have a collection that looks like this, with 100+ rows:
Results
Answer
Timestamp
8 Apr 2021
Name
ABC
I'd like to manipulate the data such that if Results = 'Name', Get the Answer (aka ABC) and put it into a data item.
Is there any way to do this?
I understand I could hardcode i.e. Get value based on Row Index and Column Index, but my data is complex and may not always have the same rox index.
Can you use the collection filter to get a collection output? The utility has an action to filter where you can input a collection and then use
[FieldName] Like "some value"
This would result in every complete row in the collection that matches the filter.

How to store a value in nested collection field in blueprism?

I need to store "x" in Item Data.Equipment Requirement.Tariff.0
Item Data is a collection which has a field of type collection "Equipment Requirement"
Equipment Requirement is a collection which has a field Tariff and filled with 6 rows.
I am sure that there is no naming errors, but each time i store something in Item Data.Equipment Requirement.Tariff.0 i got and error:
Internal : Could not store calculation result - Field Item
Data.Equipment Requirement.Tariff.0 not found
Blue Prism's dot notation only has the capability to refer to collection fields, not specific row indices. Use the Utility - Collection Manipulation VBO's Set Collection Field Action:
Business Object: Utility - Collection Manipulation
Action: Set Collection Field
Inputs:
- Row Index: 0
- Collection: Item Data.Equipment Requirement
- Field Name: Tariff
- Value: "35"
Outputs:
- Updated Collection: Item Data.Equipment Requirement

Filter container on column name

Below is COLLECTION (DATA) format:
Column A Column B. Column C
AAAA. 1234. 54
AAAA. 5678. 56
AAAA. 1234. 46
I need to loop through the container and sum up COLUMN C for matching COLUMN B.
The filter container is not working:
"[DATA] = COLUMN B"
I cannot put the filter condition on text, e.g.:
"[DATA] = '2234.'"
Also tried without double quotes:
[DATA] = COLUMN B
Is there a possible way of filtering on column name?
Reading between the lines of your post, I guess that you're having problems with filtering collection. Example of filtering can be found below:
Object: Utility - Collection Manipulation
Action: Filter Collection
Input:
Collection_in: [Data]
Filter: "[Column B.] = '1234'"
If you would like to filter collection by a variable, then it's getting a little complicated with all single and double quotation marks and concatenation of strings.
Imagine if the filtering value is stored in data item [Filter].
To filter the collection [Data] by [Filter] data item you need to use following filter:
Filter: "[Column B.] = '" & [Filter] & "'"

Set html table header as rpa collection header

Ive managed to get html table and change it to collection. However i would like for the table header to become the collection header. Is it possible to do it? Thanks.
Below is for further details on how i take the table element and change it to collection.
The path that im getting from the html table inside application modeller:
/HTML/BODY(1)/DIV(2)/FORM(2)/DIV(1)/TABLE(1)
Then i use Read stage and choose the table as the element and set Data as Get Table function and save the collection.
The collection result produces:
On header - Column1(text), Column2(text)....
First Row - Department, Name.... || This supposed to be the header
Second Row - DepartmentData, NameData....
Well, I got the action called "Set Column Names From First Row" in Utility - Collection Manipulation. Do you have it too?
If not, then here's the code:
Dim iThisColumn as integer = -1
For Each Column As DataColumn In Input_Collection.Columns
iThisColumn +=1
Column.ColumnName=CStr(Input_Collection.Rows.Item(0).Item(iThisColumn))
Next
Output_Collection = Input_Collection

Use current AutoFilter to load Data-Validation

I have a situation where i am using two Data-Validation cells which are loaded with data from one column (each) from the data table.
Table
market; suprv; store; ....
Data-Validation
cellDV1 - Unique Values from Table[market]
cellDV2 - Unique Values from Table[suprv]
Both cellDV1 & cellDV2 are preloaded with their respective unique values when the user views the worksheet.
When the user selects a value from cellDV1 then it AutoFilters the Table with the selected value. I then want to reload cellDV2 with the refined results visible in Table.
Problem i am having is that it is loading all of the Unique Values from that column/field in the Table and not the AutoFiltered results.
Usage:
LoadDataValidation Range("Table[suprv]"), Range("cellRange")
LoadDataValidation:
Dim str As String
str = DistinctValues(srcrng)
Dim val As Validation
Set val = Range(destrng.Address).Validation
val.Delete
val.Add xlValidateList, xlValidAlertStop, xlBetween, str
Any ideas, how to only select the Filtered results instead of the whole dataset in the Table?
I haven't worked with Tables very much, but can you apply the SpecialCells(xlCellTypeVisible)property to the Range
So Range("Table[suprv]").SpecialCells(xlCellTypeVisible) as your first argument in LoadDataValidation

Resources