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()
}
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()) }
}
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.