Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Fetch the last due date from sub tasks and update the due date for story



I have a story and subtasks under it. Each subtask has a due date, is there a way that I take the last date and update that due date to the story automatically? The dates of the subtask can change as the assignee keeps changing it and the date on the story should get updated. I'm using the Jira server 8.11.x version.

By the way I'm a newbie to script if I'll have to use that, but eager to pickup any possibilities.

Thanks in advance.

1 answer

I would handle this with scriptrunner.

I'd set up a listener for issue updated that checks for subtasks having their Due Date updated.

When it fires, you'll have to get the parent issue, create a list of that parent's sub-task issue objects, find the one with the greatest value (jira counts later dates as higher value) and set the parent's Due Date equal to that latest date.

Bonus points if you check the sub-tasks's new due date against the parent's existing due date first, then you don't have to set the value unless the subtask due date is later than the parent's

Thanks Padraik. Can you provide a code snippet to setup the listener?I'll try to create one by making the necessary changes.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.config.SubTaskManager

def linkMgr = ComponentAccessor.issueLinkManager
def cfManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService.class)

def issue = event.issue as MutableIssue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def change = event?.changeLog?.getRelated("ChildChangeItem")?.find{it.field == "Due Date"} // This makes "change" valid if the Due Date field was changed during the update

log.warn ("change: $change")
if (issue.getIssueType().getName() == "Sub-task" && change) // IF change is valid, and the update was made to a Sub-task
def parentIssue = issue.getParentObject() as MutableIssue // Get the parent issue
def parentIssueDueDateValue = parentIssue.getDueDate()
def parentOutwardLinks = linkMgr.getOutwardLinks( Get all of the Parent's outward links - Story has an outward link of "jira_subtask_link" to its subtasks

parentOutwardLinks.each // Step through each of the parent's outward links
if ( == "jira_subtask_link") // For issues linked with the subtask indicator link
def subtaskIssueObject = (MutableIssue) it.destinationObject // This is the subtask issue object itself
def subtaskDueDateValue = subtaskIssueObject.getDueDate() // The Value in the Subtask's Due Date

if (subtaskDueDateValue > parentIssueDueDateValue) // If the Subtask's Due Date is later than the parent issue
parentIssue.setDueDate(subtaskDueDateValue) // set the parent isue's Due Date to match the Subtask

Thank you. There is an error that says "the variable [Event] is undeclared". Can you help me to say what type of variable is that or a declare statement would be appreciated.


Thank you.

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you