Document toolboxDocument toolbox

(8.11.X) Latest issue due date

Description

Returns the latest due date of all issues in the project.

Configuration

1. Create a Projectrak Script field called "Latest issue due date"

2. Insert the following Groovy script and modify accordingly to your instance:

Groovy Script

latest_issue_due_date.groovy
package deiser.profields.scripts

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.project.Project
import com.atlassian.jira.web.bean.PagerFilter
import com.deiser.jira.profields.util.ProfieldsDateUtils

import java.time.Instant

//Get the context values
def PROJECT_ID = project.id

//Get services and manager from Jira
def searchService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchService)
def jiraAuthenticationContext = ComponentAccessor.jiraAuthenticationContext

//Get loggedInUser
def loggedInUser = jiraAuthenticationContext.getLoggedInUser()

//Create the query with its conditions
def query = JqlQueryBuilder.newBuilder().where()
        .project(PROJECT_ID)
        .and()
        .unresolved()
        .buildQuery()

//Get max Date
def maxDueDate = Instant.MIN
searchService.search(loggedInUser, query, PagerFilter.unlimitedFilter).results
        .each { issue ->
            def dueDateIssue = issue.getDueDate()
            if(dueDateIssue == null) return

            if(dueDateIssue.toInstant().isAfter(maxDueDate)){
                maxDueDate = dueDateIssue.toInstant()
            }
        }

if(maxDueDate == Instant.MIN) return "No issues with due date"

//Format Date
return ProfieldsDateUtils.formatDate(Date.from(maxDueDate as Instant), APKeys.JIRA_DATE_PICKER_JAVA_FORMAT, loggedInUser)

3. Configure the project's layout including "Latest issue due date

4. Associate the layout to the project you need this information to be applied to. 

5. The result should be something like this: (please, keep in mind that this is only an example and your results should vary from what it is shown in the screenshot).