How to Sync Date/DateTime Custom Fields in Jira Cloud

    This article shows how to synchronize Date/DateTime custom fields.

    Jira Cloud and Jira Server use different data types to store the value of the Date custom field.

    If you're exchanging the custom field value between different issue tracking platforms you need to transform the value into the proper type on the receiving side.

    Below you can find the example of a simple date custom field synchronization that works for syncing custom fields. 

    Source Side

    Jira Outgoing sync(Data Filter)

    To send the data use the code below  

    replica.customFields."My Date CF" = issue.customFields."My Date CF"

    Destination Side

    Jira Incoming sync(Create/Change processors)

    issue.customFields."My Date CF".value = replica.customFields."My Date CF".value

    If you synchronize the date custom field between Jira Cloud and Jira Server you need to transform the formatted date to the proper value type. 

    The example below shows how you can transform the received value to the timeStamp format on Jira Server. 

    Jira Server 

    Incoming sync(Create/Change processors)

    // ======= Date CF ===============
    import java.text.SimpleDateFormat;
    import java.text.DateFormat;
    
    def dateCustomFieldValue(replicaCustomField) {
        def datePattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; // define the desired date/time format
        String dateString = replicaCustomField.value;
        if (dateString) {
            dateString = dateString.replaceAll("\"","").trim();
            DateFormat formatter = new SimpleDateFormat(datePattern);
            date = formatter.parse(dateString);
            return new java.sql.Timestamp(date.time);
        }
    }
    
    issue.customFields."My Date CF".value = dateCustomFieldValue(replica.customFields."My Date CF");
    // ======= Date CF ===============



    How to sync Date/Datetime in Exalate for Salesforce

    It is required to convert the value into a Long. The incoming script will be different depending on the sending side.

    As an example, we will use Jira to Salesforce sync:

    Jira Outgoing sync rules

    replica.customFields."DateCf" = issue.customFields."DateCf"
    replica.customFields."DateTimeCf" = issue.customFields."DateTimeCf"

    Salesforce Incoming sync rules

    import java.text.SimpleDateFormat;
    import java.text.DateFormat;
      
    def dateCustomFieldValue(replicaCustomField) {
        def datePattern = "yyyy-MM-dd HH:mm:ss.S"; // define the desired date/time format
        String dateString = replicaCustomField.value;
        if (dateString) {
            dateString = dateString.replaceAll("\"","").trim();
            DateFormat formatter = new SimpleDateFormat(datePattern);
            date = formatter.parse(dateString);
            return date.time;
        }
    }
     
    entity.date__c = (Long) dateCustomFieldValue(replica.customFields."DateCf")
    entity.datetime__c = (Long) dateCustomFieldValue(replica.customFields."DateTimeCf")


    Salesforce Outgoing sync rules 

    replica.date__c = entity.date__c
    replica.datetime__c = entity.datetime__c

    Jira Incoming sync rules

    issue.customFields."DateCf"?.value = (Long) replica.date__c
     issue.customFields."DateTimeCf"?.value = (Long) replica.datetime__c