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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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] ..." ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Be sure that you have "Issue updated" selected as your Event in the listener:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.