Requirement:
Need a scripted field to hold the original due date of the issue (due date setup at the time of issue creation)
I am pretty close to the solution, however, stuck with one error.
Script written below to check the issue history for any updates to 'Due Date'. If no, it returns the current Due date on the issue, else, returns the 'FromValue' from the first history entry for Due Date changes.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean
import static com.atlassian.jira.issue.IssueFieldConstants.*
import static java.lang.Math.*
import java.sql.Timestamp
import java.text.SimpleDateFormat
import java.text.DateFormat
import java.util.Date
def cf1 = issue.getDueDate()
def cf2 = new Date(cf1.time)
String fieldName = 'duedate'
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
List<ChangeItemBean> changeItems
changeItems = changeHistoryManager.getChangeItemsForField(issue, fieldName)
if (changeItems.size()> 0)
{
def first_change=changeItems.sort(false).first()
def value=first_change["fromValue"]
return value
}
else
{
return cf2
}
I am using the below selection:
Template: Custom
$datePickerFormatter.withStyle($dateTimeStyle.DATE).format($value)
Search Template: Date Time Searcher
Error: Getting the error for return of 'value' : Cannot return value of type java.lang.Object on method returning type java.util.Date.
Note: no such error for return of 'cf2'
Any help is much appreciated. Thanks!
Hello @Neetika Kumar
Did you try adding logs and then executing the script in the script console.
Also, for changeHistoryManager why is the sorting used because as per the docs
Returns a List of ChangeItemBean's for the given issue which also are for the provided changeItemFieldName (i.e. Link, Fix Version/s, etc). The order of the list will from oldest to newest.
It returns ChangeItemBean
Which has the method
String getFrom()
Can you execute this in the console and share what's being returned it should be a date value as string.
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.