cancel
Showing results for 
Search instead for 
Did you mean: 

#BPTechTips - Wondered How Collections Can Be Used As Dictionaries!

Hi All,

A small hack that I use especially for reading configuration files at times where I convert the usage of my collection similar to that of a dictionary.

Suppose I have a configuration file like shown below:

26733.png

What I do is read the above table data into a collection by creating instance, opening workbook and reading the entire thing into a collection using 'Get Worksheet As Collection' action.

Now comes the little hack that I do!!

Create a custom action by extending the Collection Manipulation VBO with the below code:

26734.png
26735.png
Use the below code :

Dim newRow As System.Data.DataRow

For each row as System.Data.DataRow In Collections.Rows
      newCollection.Columns.Add(CStr(row("Name")) ,GetType(String))
Next
newRow = newCollection.NewRow()

For each column as System.Data.DataColumn In newCollection.Columns
    For each row as System.Data.DataRow In Collections.Rows
       If CStr(row(0))=column.ColumnName
          newRow(column.ColumnName)=CStr(row(1))
       End If
    Next
Next

newCollection.Rows.Add(newRow)


Let us see the results shall we:

After reading the excel file:

26736.png

Post calling the action:


26737.png

Now you can guess what is the best part here? If you need to use any configuration variable, simply write: [CollectionName.VariableName] and this way I am using my collection as a dictionary: "Provide a key, get the value"

Let me know if you like it!

#BPTechTips #Quick_Tip

------------------------------
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

----------------------------------
1 REPLY 1

I really liked it. Try it for sure.
Currently, I perform such a task for configuration files using Append Field action to transpose collection.
Thanks for sharing.

------------------------------
Thanks & Regards,
Tejaskumar Darji
Sr. RPA Consultant-Automation Developer
------------------------------