1
0
-1

Hello,

I've got an error as below:
"Cannot cast object '2020-12-03 13:43:48' with class 'java.lang.String' to class 'java.util.Date' "


It appeared after I added to SN outoging sync rule line:


replica.created = incident.u_reported_date_time


SN incoming sync rule line looks as below:


incident.u_reported_date_time = replica.created


In SN field u_reported_date_time is a date/time type.

    CommentAdd your comment...

    4 answers

    1.  
      2
      1
      0

      Jira sent unix Time stamp 1613484000000 to ServiceNow.
      ServiceNow converted it to 16th Feb 3 AM instead to 16th Feb 3PM.

      When ServiceNow sends time stamp to Jira, it shows correct time.

      We see time difference of 12 Hours in ServiceNow.


      Method used for above test:


      import java.text.SimpleDateFormat

      def timestamp = (replica.customFields."Reported Date"?.value) //millisecondsdefsdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")

      sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")

      def targetDate

      if (replica.customFields."Reported Date"?.value)

      {

         targetDate = sdf.format(replica.customFields."Reported Date"?.value)

         incident.u_reported_date_time = targetDate

      }


      After some tests and checks here (https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) it appeared that we need to have Capital "H" for Hours to reflect the 24 Hours Format.


      sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

        CommentAdd your comment...
      1.  
        1
        0
        -1

        I apologize for the simplistic question, but how did this work in the incoming and outgoing scripts?


          CommentAdd your comment...
        1.  
          1
          0
          -1

          The issue was solved by changing the simple Date format to "yyyy-MM-yy HH:mm:ss"

          The capital "H" was required as ServiceNow setting is 24 hours format, and not 12 hours format.

            CommentAdd your comment...
          1.  
            1
            0
            -1

            Hi Andrew


            The string needs to be converted to date
            Always a good testbed to try out groovy scripts is 
            https://groovyconsole.appspot.com/

            Check out following code

            Untested
            import java.text.SimpleDateFormat
            
            def sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
            Date date = sdf.parse("2020-12-03 13:43:48")
            
            
            print "Date = ${date​​​​​​​​​​​​​}"​
            


            Results in


              CommentAdd your comment...