Rename Collection Fields In BluePrism

Eoin2211 picture Eoin2211 · May 9, 2018 · Viewed 7.3k times · Source

enter image description hereI have an excel worksheet where I am using get Worksheet Range as a Collection. However, the excel file does not have column names. After reading the sheet I want to change the collection field names. I have tried using Rename Collection Fields but this doesn't seem to work?

Answer

Badda_Bing picture Badda_Bing · May 9, 2018

If you leave a blank row at the top of your range BP will assign column names (Column1, Column2, etc...) from left to right. With this you could do the following after you get your output collection out of "Get Range as Collection" stage:

1) - Create 1 Data Item for each column name you wish to insert into the collection.
- Select the appropriate Data Type and enter the desired column name into the Value field of each Data Item.

2) - Insert a new blank Collection item and name it something like "Field Names".
- In this Collection, under the Fields tab add 1 field for each column name.
- Then name each field from top to bottom as Column1, Column2,etc..(no spaces) and also select the appropriate Data Type for each.
- Finally, under the Initial Values tab enter a new black row using the Add Row button.

3) - Now insert a MultiCalc stage after your "Get Range as Collection" stage.
- Using the Add button, create as many lines as Data Items you created earlier in step1.
- In the Expression field, drag and drop each Data Item you created earlier.
- In the Store In field, point to the collection you created in step2 and the "raw" name of the column as given by BP, for example FieldNames.Column1, FieldNames.Column2, etc...

4) - Insert a new Action stage after the MultiCalc and name it something like "Rename Fields".
- As the Business Object, select the "Utility - Collection Manipulation".
- As the Action, select "Rename Collection Fields".
- As the Main Collection, drag and drop your original output collection that you obtained out of the "Get Range as Collection" stage.
- As the New Headers, drag and drop the "Field Names" collection you created in step2.
- Finally under the Output Tab, create (or drag in) the output collection and name it something like "Amended Collection".

If you use MSExcelVBO/WriteCollection to write the "Amended Collection" into Excel, you will see that your data now has the column names of each data item. For example here is a list without headers and I want the headers to be Names and Percentage (see data items in blue below): StudentsNoHeaders
Here is the process I've explained: BP ProcessMain

The Get Range As Collection stage (Inputs tab): GetRangeAsCollectionInputs
The Get Range As Collection stage (Outputs tab): GetRangeAsCollectionOutputs The Field Names collection (Fields): FieldNamesCollectionFields The Field Names collection (Initial Values): FieldNamesCollectionInitialValues
The MultiCalc stage: MultiCalc The Rename Collection Fields stage (Inputs): RenameCollectionFieldsInputs The Rename Collection Fields stage (Outputs): RenameCollectionFieldsOutputs And finally the Write Collection stage: WriteCollectionStage And the result: StudentsHeaders