xl8bot
1
Originally asked by Andrew on 07 December 2020 (original question)
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.
xl8bot
2
Answer by Andrew on 23 February 2021
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”)
xl8bot
3
Answer by Robert Horan on 24 November 2021
I apologize for the simplistic question, but how did this work in the incoming and outgoing scripts?
xl8bot
4
Answer by Anja Palutke on 01 March 2021
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.
xl8bot
5
Answer by Francis Martens (Exalate) on 07 December 2020
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
xl8bot
Closed
6
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.