2
1
0

Hi I am trying to sync a datetime field in Jira with a date field in zendesk (bi-directionally) since Zendesk doesnt support date time fields.


Ideally in the future I would like to sync the "Time" portion as maybe a text field in zendesk but for now I just want the date to set the datetime in JIRA (I am okay if it always sets a default time as long as the date is correct)


Here is my current setup:

JIRA Outgoing Sync:

replica.customFields."Outage Start Time" = issue.customFields."Outage Start Time" 

JIRA Incoming Sync:

issue.customFields."Outage Start Time".value = replica.customFields."Outage Start Time"?.value 


Zendesk Outgoing Sync:

replica.customFields."Outage Start Time" = issue.customFields."Outage Start Time" 



Zendesk Incoming Sync:

issue.customFields."Outage Start Time".value = replica.customFields."Outage Start Time"?.value


Its currently syncing back and forth but for some reason the datetime value in Jira is the day before the date in zendesk.

Syncing from Jira to zendesk sets the proper date value but syncing from zendesk to Jira doesnt.

For example,

Date in Zendesk is changed to  16/Jul/20

DateTime in JIRA = 15/Jul/20 5:00 PM

  1. André Leroy-Beaulieu Castro

    Hi Spencer,


    Could it be that the date internally in Jira is in a different timezone than zendesk? Because the datetime is sent as a timestamp and the Jira interprets it according to it's timezone, so if there's an hours difference that makes it seem like its the day before in Jira then that's how it will be set.


    Thanks,


    André

  2. Spencer Johnson

    André Leroy-Beaulieu Castro  I got the fields working but I am trying to convert a string date in EST time to a date (timestamp) in PST time but am running into issues


    Do you know how to convert a string representing a date (ie. '2020-10-25-11:45:00') in EST to a timestamp in PST so I can set it in JIRA.


    Zendesk is in EST but JIRA is in PST

CommentAdd your comment...

2 answers

  1.  
    1
    0
    -1

    Here is how I ended up synching a Date/Time field in JIRA (in PST) with a text field in Zendesk (representing a date time value entered in EST)

    Fields

    Zendesk Field: "Outage Start Date" (Text field)

    JIRA Field: "Outage Start Time" (Datetime field)


    Example

    Entered in Zendesk: 07/11/2020 11:30:00 PM

    Value in JIRA: 11/Jul/20 8:30 PM

    Zendesk

    Zendesk Outgoing Sync:

    replica.customFields."Outage Start Date" = issue.customFields."Outage Start Date" 

    Zendesk Incoming Sync:

    // ======= Date CF ===============
    import java.text.SimpleDateFormat
    import java.text.DateFormat
    import java.util.Date
    import java.util.TimeZone
    
     // Date Sync Function
    def convertDateTimeToString(issueCustomField){
        def dateString = issueCustomField?.value;
        if (dateString) {
            def date = new Date(dateString.getTime())
            SimpleDateFormat dateFormat = new SimpleDateFormat( "MM/dd/yyyy hh:mm:ss a")
            dateFormat.setTimeZone(TimeZone.getTimeZone("US/Eastern"))
            if (date != null) {
                String dt = dateFormat.format(date)
                if (dt != null) {
                    return dt;
                }
            }
        }
    }
    
    def outageStartTime = convertDateTimeToString(replica.customFields."Outage Start Time")
    if (outageStartTime != null){
        issue.customFields."Outage Start Date".value = outageStartTime
    }
    
    


    JIRA

    Jira Outgoing Sync:

    replica.customFields."Outage Start Time" = issue.customFields."Outage Start Time"

    Jira Incoming Sync:

    // ======= Date CF ===============
    import java.text.SimpleDateFormat
    import java.text.DateFormat
    import java.util.Date
    import java.util.TimeZone
    
    def convertToDateTime(replicaCustomField){
        def dateString = replicaCustomField?.value
        DateFormat formatter= new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a")
        formatter.setTimeZone(TimeZone.getTimeZone("US/Eastern"))
        if (dateString != null) {
            def date = formatter.parse(dateString)
        
            // Set the formatter to use a different timezone 
            formatter.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"))
            def dt = formatter.format(date)
            def date2 = formatter.parse(dt);
            def ts = date2.toTimestamp()
            if (ts != null) {
                return ts
            }  
        }
    }
    
    def outageStartTime = convertToDateTime(replica.customFields."Outage Start Date")
    if (outageStartTime != null){
        issue.customFields."Outage Start Time".value = outageStartTime
    }
      CommentAdd your comment...
    1.  
      1
      0
      -1

      Spencer Johnson I used your code, but I am getting the below error

      The only difference if that I want to Sync from ZD→ Jira(cloud) only and Date is Zendesk is "Date picker"


      I posted more details here

      image2023-6-14_12-19-47.png

        CommentAdd your comment...