Forums

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

Need a script to calculate Days (Due date - Reported date)

Abdul Mannan Mohammed
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 23, 2023

Hi team,

I need a scripted field to calculate the days from Due date - Reported date(Custom field).

I have a script which calculates todays date - Reported date(script is given below).

Can you please help me in modifying the script to get the exact request.

Script:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def createdDateValue = issue.getCreated()
def resolutionDate = issue.getResolutionDate()

def issueReportedDate = customFieldManager.getCustomFieldObject("customfield_17705")

def issueReportedDateValue = issue.getCustomFieldValue(issueReportedDate)


if (issueReportedDateValue != null) {

if (resolutionDate != null) {

def daysDiff = resolutionDate - issueReportedDateValue

return daysDiff
}
else {
def daysDiff = new Date() - issueReportedDateValue
return daysDiff
}

}

return null

1 answer

0 votes
Albert Manuel
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2023

I didn;t tried it but made some small adjustments which should help:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def dueDateValue = issue.getDueDate()
def issueReportedDate = customFieldManager.getCustomFieldObject("customfield_17705")
def issueReportedDateValue = issue.getCustomFieldValue(issueReportedDate)

if (issueReportedDateValue != null && dueDateValue != null) {
def daysDiff = dueDateValue - issueReportedDateValue
return daysDiff
}

return null

Suggest an answer

Log in or Sign up to answer