Forums

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

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

Vasanthram June 21, 2022

Hello,

 

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

0 votes
padraik
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.
June 21, 2022

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

Vasanthram June 21, 2022

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

padraik
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.
June 22, 2022

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(parentIssue.id)// 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 (it.issueLinkType.name == "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
}
}
}
}

Vasanthram June 28, 2022

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.

Antoine Berry
Community Champion
July 7, 2022

Hello @Vasanthram if you are using this script in a listener, there should be no problem with the "event" variable as it will exist at execution time. Are you sure the the E is capital in the error "the variable [Event] ..." ?

padraik
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.
July 7, 2022

Be sure that you have "Issue updated" selected as your Event in the listener:

Annotation 2022-05-10 143031.png

Suggest an answer

Log in or Sign up to answer