1
0
-1

Hi Exalate community,


Currently I am trying to fetch the opened_at from ServiceNow and sync it to the start date field of Azure DevOps. This turned out to be more difficult than expected. The opened_at field is fetched from ServiceNow as a string field, with the pattern ...


By replacing the / with - it is formatted in the way Azure DevOps should accept it. When trying to sync Azure DevOps throws the following error:


TF401326: Invalid field status 'InvalidType' for field 'Microsoft.VSTS.Scheduling.StartDate'. 


I then set out to parse it to a date via below code:


def dateConverter(replicaForConvert) {

  def datePattern = "dd-MM-yyyy hh:mm:ss"

      def dateString = replicaForConvert

      if (dateString) {

          dateString = dateString.replaceAll("/","-");

          DateFormat formatter = new SimpleDateFormat(datePattern);

          date = formatter.parse(dateString);

          Timestamp timestamp = new Timestamp(date.getTime());

          return timestamp;


This gives me the following example:

2023-01-16 14:31:06.0


It adds milliseconds at the end and Azure DevOps does not like this, it won't accept this as a valid input. It doesn't give the same error anymore because it is recognized as a date field but it just doesn't fill the field without an error.


How do i get rid of the millisecond at the end whilst keeping this as a date type and not transforming it to a string?


Thanks in advance for the help.


Cheers,


Robbert

    CommentAdd your comment...