Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

scripted field to return 'due date' saved at issue creation

Neetika Kumar August 23, 2018

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!

 

 

 

 

 

 

 

 

 

1 answer

0 votes
Tarun Sapra
Community Champion
August 23, 2018

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 

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/history/ChangeItemBean.html

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events