cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Data type of Column Name

vinodchinthakin
Level 9
Hi

I have a Collection with Columns A,B,C as Text Data Type. I want to convert Column B as Number Data Type.
I am using Calc stage within a loop which is taking more time when collection is huge. Do we have any other solution for this ?

Thanks

------------------------------
vinod chinthakindi
------------------------------
16 REPLIES 16

Hi Ashis,

Yes you are absolutely correct on the point that the values which got converted are in UTC format because of which you are facing this issue. Also, one thing to note is in VB .NET you only have the DateTime class. Technically speaking, even the Date values are treated as DateTime objects with time component values as 00:00:00 only which is why when we call the data type in VB .NET then it is by default mapped against the DateTime column in the collection.

My fair guess here is that Blue Prism internally has some mechanism of converting the DateTime objects into the the 'Date' data type at the Blue Prism end or they might be using some specific class for dates that I am not aware of yet.

Perhaps @Bruce Liu @ewilson or someone from the technical team can confirm which class type in VB .NET is specifically being used to map the data type 'Date' in Blue Prism.


Coming to one of the solution is probably something you have picked up correctly that we would require to convert the incoming date from UTC format. For implementing this I have modified by solution a bit as shown below:

27377.png

First you need to create all this extra data items as input parameters for the action where you can supply the time difference in terms of hours, minutes and seconds​. You can provide the default value as 0 (Initial Value). So tomorrow in case you want to work with UTC format simply no need to provide any values.


In the code stage also the following changes need to be done:

27378.png

27379.png

27380.png27381.png

Here the major change is the commenting of the line: Output_Collection.ImportRow(row) and instead we are using a different looping logic altogether so that we can check the date data type and accordingly convert just that one column value to Local format instead of importing all the rows at once.

For Each column As System.Data.DataColumn In Input_Collection.Columns

    If Field_Name.Equals(column.ColumnName) Then

         If CStr(Field_Type).ToUpper.Equals("TEXT") Then
              Output_Collection.Columns.Add(column.ColumnName,GetType(String))
         ElseIf CStr(Field_Type).ToUpper.Equals("NUMBER") Then
              Output_Collection.Columns.Add(column.ColumnName,GetType(Integer))
         ElseIf CStr(Field_Type).ToUpper.Equals("FLAG") Then
              Output_Collection.Columns.Add(column.ColumnName,GetType(Boolean))
         ElseIf CStr(Field_Type).ToUpper.Equals("DATE") Then
              Output_Collection.Columns.Add(column.ColumnName,GetType(Date))
          Else
              Throw New Exception("Invalid File Type Provided")
          End If

    Else

          Output_Collection.Columns.Add(column.ColumnName,column.DataType)

    End If

Next

Dim newRow As System.Data.DataRow

For Each row as System.Data.DataRow In Input_Collection.Rows

     newRow = Output_Collection.NewRow()


     For Each column as System.Data.DataColumn In Output_Collection.Columns

          If column.DataType = GetType(Date) Then

               newRow(column.ColumnName) = CDate(row(column.ColumnName)) + New  TimeSpan(0,Time_Difference_In_Hours,Time_Difference_In_Minutes,Time_Difference_In_Seconds)

          Else

               newRow(column.ColumnName) = row(column.ColumnName)

          End If

     Next

     Output_Collection.Rows.Add(newRow)

Next


Test Results:

27382.png
27384.png
Here I am converting UTC to IST so I have provided the time difference of +5:30, you can also provide negative values if your target time zone is behind the UTC time zone

27386.png

You can see we got the proper datetime values now since we are considering them to be a part of our current Time Zone. Hope it helps you out!

------------------------------
----------------------------------
Hope it helps you and if it resolves you query please mark it as the best answer so that others having the same problem can track the answer easily

Regards,
Devneet Mohanty
Intelligent Automation Consultant
Blueprism 6x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.

There's nothing super special going on behind the scenes within Blue Prism. As you can see from a Code stage, Blue Prism's Date, DateTime, and Time data items are all implemented using System.DateTime.

27414.png

27415.png

Cheers,

------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Thanks a lot for your response @ewilson. I had my doubts over this, but the implementation of Date from DateTime is something that is the same in VB .NET as well.

Let me rephrase my question a bit, the part that I am not able to understand is that when we try to add any columns to a data table from code stage using: Output_Collection.Columns.Add(column.ColumnName, GetType(Date))

Blue Prism adds this column as a DateTime type of column at it's end. If you say that the data types DateTime, Date and Time are all implemented using System.Date.DateTime, then how does it distinguishes that whether date, date time or time type of data is added using Columns.Add method.

Can you perhaps help to share any sample code where we can see the logic to add any Date or Time column apart from DateTime column via code stage if possible ?


------------------------------
----------------------------------
Hope it helps you and if it resolves you query please mark it as the best answer so that others having the same problem can track the answer easily

Regards,
Devneet Mohanty
Intelligent Automation Consultant
Blueprism 6x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.

I've been tinkering around a bit with this. If you look at the schema of the underlying DataTable for a Blue Prism Collection defined with a Column of type Date what you'll find in an extended property. This extended property seems to be what BP uses to map DateTime to Date and Time types.

27476.png
When you create a column dynamically there's a property on the DataColumn type called ExtendedProperties. In theory, you should be able to add this custom property to that property collection and voila. 🤷‍♂️  

Cheers,

------------------------------
Eric Wilson
Director, Integrations and Enablement
Blue Prism Digital Exchange
------------------------------

Finlay_lucaFinl
Level 2

 Once we  created using external data, systematically numeric columns are taken to as data type objects instead of int or float, creating numeric tasks not possible. We will pass any Python, Numpy, or Pandas datatype to vary all columns of a dataframe thereto type, or we will pass a dictionary having column names as keys and datatype as values to vary the type of picked columns.

Here  function empowers us to be express the data type you need to have. It's extremely adaptable i.e you can attempt to go from one type to some other.

 Attention geek! Strengthen your foundations with the Course and learn the basics.

Jaychlo
Level 3

Hi Vinod. 

I'm curious as to how you used a loop and calc stage to change the Data Type of your column. I need to do this myself. It could be any column that needs to be changed and it could be a different column every time.
Any help would be appreciated. 

Thanks
JB

Hi Devneet, 

I've tried using your code below to update a data type in my collection but I'm getting the error below:

Description: Compiler error at line 20: 'Output_Collection' is not declared. It may be inaccessible due to its protection level.

Any suggestions and how I can correct this please?