cancel
Showing results for 
Search instead for 
Did you mean: 

Trim And Rename Collection Field Names

vinodchinthakin
Level 9
Hi All. 

I have a collection with 20 columns. I want to rename all of them with same names in Upper or Lower case and also want to trim the field names using a code stage.

can anyone have a solution?

------------------------------
vinod chinthakindi
------------------------------
1 BEST ANSWER

Best Answers

Hello,

I just figured out the code. Following code helps me to achieve my requirement. I just tweaked Rename Field Action code.

Collection_Out = Collection_In.Copy

 For Each c As DataColumn in Collection_Out.Columns

                c.ColumnName = Trim(c.ColumnName).ToUpper

                Exit For           

Next



------------------------------
vinod chinthakindi
------------------------------

View answer in original post

6 REPLIES 6

CarlCarter
Staff
Staff
Hi Vinod,

You could get a list of the current column names using the 'Get Collection Fields' action. You could then Loop the collection, formatting the values to meet your requirement. Then, call the 'Rename Collection Fields' action passing the data Collection and the Collection containing the formatted column names to the action.

------------------------------
Carl Carter
Senior Developer
Blue Prism
Europe/London
------------------------------

Hi Vinod,

As Carl says, this is the easiest option, you can use the following functions in a calculation stage within a loop to do this such as

Trim(Lower([collection.Name]))

or

Trim(Upper([collection.Name]))



------------------------------
Ronan Considine
Senior Business Analyst
Blue Prism
------------------------------
Ronan Considine Senior Business Analyst Blue Prism

Hi @CarlCarter @Ronan Considine. This logic seems time consuming for me. I couldn't able to achieve it properly.

If possible could pls try it in your blue prism and share screenshots of process action steps . Want to look how its achieved.

Instead of Loops, Do we have any code stage for this?​

------------------------------
vinod chinthakindi
------------------------------

Hello,

I just figured out the code. Following code helps me to achieve my requirement. I just tweaked Rename Field Action code.

Collection_Out = Collection_In.Copy

 For Each c As DataColumn in Collection_Out.Columns

                c.ColumnName = Trim(c.ColumnName).ToUpper

                Exit For           

Next



------------------------------
vinod chinthakindi
------------------------------

Hi Vinod,

When there is a solution which doesn't require custom code, then I would always offer this first unless there was a major performance gain from using a code stage. This is so more of the community can make use of the solution without needing to understand .NET code.

Well done in figuring out the custom code. I can see there is an issue with your code though. Your 'Exit For' command will exit your 'For Loop' after the first column name has been renamed. You should remove the 'Exit For' command unless it is your intention to only rename the first column.

------------------------------
Carl Carter
Senior Developer
Blue Prism
Europe/London
------------------------------

Thanks Carl for the suggestion.
I have updated my code and also included Flags for Trim and Uppercase using If else condition within for loop. Now its working well.

------------------------------
vinod chinthakindi
------------------------------