Help with Setting Due Date in Jira using Exalate

Originally asked by Kaleigh Garcia on 03 July 2024 (original question)


Hello everyone,

I’m having trouble setting the due date in Jira using Exalate. The script below is a simplified version focusing on formatting and setting the due date.

The formatDueDate function converts the date from MM/dd/yyyy to yyyy-MM-dd, and I’m trying to ensure that the due date is set for the CSU project. However, this logic is not working as expected. Can anyone provide guidance on the correct way to set the due date in Jira using Exalate? Are there any common issues or best practices I should be aware of?

Thanks in advance!

import java.text.SimpleDateFormat
import java.text.DateFormat

def formatDueDate(dueDate) {
    if (dueDate) {
        try {
            def datePattern = "MM/dd/yyyy"
            String dateString = dueDate.toString()
            dateString = dateString.replaceAll("\"", "").trim()
            DateFormat formatter = new SimpleDateFormat(datePattern)
            Date date = formatter.parse(dateString)
            return new SimpleDateFormat("yyyy-MM-dd").format(date)
        } catch (Exception e) {
            return null
        }
    }
    return null
}

if (firstSync) {
    issue.projectKey = replica.JiraProjectKey__c

    if (replica.JiraProjectKey__c == "CSU" && replica.DueDate__c) {
        def formattedDueDate = formatDueDate(replica.DueDate__c)
        if (formattedDueDate == null) {
            throw new IllegalArgumentException("Due date is required for 'PROD Stand up' issue type in project 'CSU'")
        } else {
            issue.duedate = formattedDueDate
        }
    }

    syncHelper.syncBackAfterProcessing()
}



Answer by Juan Carvajal on 08 July 2024

Found 2 issues with the script, one with the due date internal name in Jira (appearing as “issue.due”) and the second with the java constructor interpreting the date as double format (the correct format was forced through the use of “.longValue()”), the corrected script would be the following:

import java.text.SimpleDateFormat
import java.text.DateFormat

def defaultUser = nodeHelper.getUserByEmail("jira.salesforce@qualifacts.com")

def dateCustomFieldValue(dueDate) {
    if (replica.dueDate) {
        try {
            def datePattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" // define the desired date/time format
            String dateString = replica.dueDate.toString()
            dateString = dateString.replaceAll("\"", "").trim()
            DateFormat formatter = new SimpleDateFormat(datePattern)
            Date date = formatter.parse(dateString)
            return new java.sql.Timestamp(date.time) // Return a java.sql.Timestamp object
        } catch (Exception e) {
            // Handle parsing exception if necessary
            return null
        }
    }
    return null
}

if (firstSync) {
    issue.projectKey = replica.JiraProjectKey__c

    // Add conditions to determine the typeName based on Category_Text__c
    if (replica.JiraProjectKey__c == "CSU") {
        issue.typeName = "PROD Stand up"
        issue.summary = "[${replica.JiraProjectKey__c}]: ${replica.Sub_Category_Text__c} - ${replica.summary}"

        // Ensure due date is set
        if (replica.dueDate) { issue.due = new Date(replica.dueDate.longValue()) }   
    }

Comments:

Kaleigh Garcia commented on 08 July 2024

Thanks, Juan Carvajal !

Answer by Kaleigh Garcia on 04 July 2024

Sonal Otwani , I am receiving the following error: While trying to create an issue of type ‘PROD Stand up’ in project ‘CSU’ for remote ‘a7KTR000003Hu2T2AS’, Jira responded with: Field Due date is required.: duedate.


Comments:

Sonal Otwani commented on 05 July 2024

Hey Kaleigh Garcia

Can we have a short call for this please?

This is my Calendly link:

https://calendly.com/sonal-otwani-0cfc

you can book a slot and then we can continue.

Thanks,

Sonal

Answer by Sonal Otwani on 04 July 2024

Hey Kaleigh Garcia

Hope you are doing good.

Can I ask you few questions about the issue ?

Are you facing error in your script ? or is this just the date is not being converted in the expected format ?

Can you please describe the issue in more details ?

Kindly let me know in case of any concerns.

Thanks,

Sonal


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.