Questions for Confluence license has expired.

Please purchase a new license to continue using Questions for Confluence.

Help with Setting Due Date in Jira using Exalate

 
1
0
-1

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


    CommentAdd your comment...

    3 answers

    1.  
      1
      0
      -1

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


      CommentAdd your comment...
    2.  
      1
      0
      -1

      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.

      1. Sonal Otwani

        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

      CommentAdd your comment...
    3.  
      1
      0
      -1

      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 

        CommentAdd your comment...