I have a Script which gets the value of DueDate (Jira Default Field) and calculates the value out from Present Date and.
********************************************************************
import com.atlassian.jira.issue.Issue
import groovy.time.TimeCategory
import groovy.time.TimeDuration
import java.text.SimpleDateFormat;
// Get a pointer to the current issue and extract the Due Date as a string
Issue issue = issue
Date dueDate = issue.getDueDate()
// Get the current date and time
Date today = new Date()
// Work out the number of days between the current date and the due date
def daysBetween = dueDate - today
*********************************************************************
Need some help updating this code to extract a Custom Field (Date Value) instead of Default DueDate Field.
Basically, how do i extract a Custom field (A Date Type) Value out?
Trying to replace DueDate (Default Field) with DateTypeField (Custom Field).
Hey Vinay
Should be something like
def cfName = "First DateTime"
//get the custom field with name First DateTime
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.find { it.name == cfName }
if (! cf) {
log.debug "Custom field with name $cfName doesn't exist"
return
}
// get the value of the custom field
def dateValue = issue.getCustomFieldValue(cf) as Timestamp
Date today = new Date().toTimestamp()
def daysDiff = today - dateValue
log.debug daysDiff
Hi Thanos,
Thank you for the input,
I have the following error while trying to executing the provided code:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The timestamp import is missing, add the following in your existing imports
import java.sql.Timestamp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thanos,
It Worked, it also made me add Component Accessor Import.
But, The Results display null for the Preview.
Not Sure the Differences in the Date Types is causing this issue or something else
For the case above it should display a Result: 84 instead it is displaying null.
Requested_DueDate(06/15/18) - Created (03/22/18) = 84
Any thoughts/Advises.
Thanks
Vinay Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.