When I update the sub task's due date longer than the parents due date, is it possible to make the parents' due date same with the sub-task which is the longest in sub-tasks.

Sangjun Jeon January 11, 2016

When I update sub task's due date longer than the parents due date,

is it possible to automatically make the parents' due date same with the sub-task which is the longest in sub-tasks?

5 answers

0 votes
Vasiliy Zverev
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.
January 12, 2016

So, here is a script which 

  • find parent issue for a subtask
  • find max dueDate of all subtasks
  • set this date to parent issue

It means that this script has to be postfunction on transition to change subtask due date. Since you have to add this postfunction to every transition. It is better to have the only transition to change due date. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

import java.sql.Timestamp

/**
 * Set max DueDate of all subtasks to parent issue
 */

Issue issue = null;
//Get parent issue
MutableIssue parentIssue = issue.getParentObject();

//Get max due date of all subtasks
Timestamp maxSubtakDueDate = issue.getDueDate();
for(Issue subtask : parentIssue.getSubTaskObjects())
    if( (subtask.getDueDate() != null) && (subtask.getDueDate().after(maxSubtakDueDate)))
        maxSubtakDueDate = subtask.getDueDate();

//Update parent if requred
if(parentIssue.getDueDate().equals(maxSubtakDueDate)){
    parentIssue.setDueDate(maxSubtakDueDate);
    ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser(), parentIssue,EventDispatchOption.ISSUE_UPDATED, false)
}

P.S.

It is possible to use sime event listener and execute this script on any issue update event, but I do not do it before.

Sangjun Jeon January 13, 2016

Thanks a million! I will try with that code. I don't forget your name. I remember it. I owe you a lot.

James Fishwick September 14, 2016

For "if( (subtask.getDueDate() != null) && (subtask.getDueDate().after(maxSubtakDueDate)))" I get a static type checking error. "reference to method is ambiguous." Ideas?

Vasiliy Zverev
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.
September 14, 2016

Try this one

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

import java.sql.Timestamp

/**
 * Set max DueDate of all subtasks to parent issue
 */

//Comment it into postfunction
Issue issue = ComponentAccessor.getIssueManager().getIssueObject("");
//Get parent issue
MutableIssue parentIssue = issue.getParentObject();

//Get max due date of all subtasks
Timestamp maxSubtakDueDate = parentIssue.getDueDate();
for(Issue subtask : parentIssue.getSubTaskObjects())
    if( (subtask.getDueDate() != null) && (subtask.getDueDate().after(maxSubtakDueDate)))
        maxSubtakDueDate = subtask.getDueDate();

//Update parent if requred
if(parentIssue.getDueDate().equals(maxSubtakDueDate)){
    parentIssue.setDueDate(maxSubtakDueDate);
    ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser(), parentIssue,EventDispatchOption.ISSUE_UPDATED, false)
}
James Fishwick September 15, 2016
MutableIssue parentIssue = issue.getParentObject();

Cannot assign value of com.atlassian.jira.issue.Issue to variable of type com.atlassian.jira.issue.MutableIssue

( subtask.getDueDate() != null )

Reference to method is ambigious. Cannot choose between boolean java.sql.Timestamp#equals(java.lang.Object) , java.sql.Timestamp#equals(java.sql.Timestamp)


James Fishwick September 15, 2016

Also, how do I target just due date changes in a postfunction?

Vasiliy Zverev
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.
September 15, 2016

For postfunction it is possible to use more simple code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

import java.sql.Timestamp

/**
 * Set max DueDate of all subtasks to parent issue
 */

//Comment it into postfunction
//Issue issue = ComponentAccessor.getIssueManager().getIssueObject("");
//Get parent issue
MutableIssue parentIssue = issue.getParentObject();

//Get max due date of all subtasks
for(Issue subtask : parentIssue.getSubTaskObjects())
    if( (subtask.getDueDate() != null) && (subtask.getDueDate().after(parentIssue.getDueDate())))
        parentIssue.setDueDate(subtask.getDueDate());
Artur Martins March 7, 2017

i'm trying to make something like this, but in my case I need a script just to change the subtask due date when I change my parent issue due date, I need the same date...How can I do?

Deepak Maharana June 25, 2019

For some reason "parentIssue.setDueDate(subtask.getDueDate())" does not work. Referred the solution given in https://community.atlassian.com/t5/Answers-Developer-Questions/Update-subtask-due-date-when-parent-issue-due-date-updated/qaq-p/481579. The below code checks the subtask with most future date and updates the parent issue.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
import org.apache.log4j.Logger
import org.apache.log4j.Level

def
log = Logger.getLogger("")
log.setLevel(Level.DEBUG)
/**
* Set max DueDate of all subtasks to parent issue

*/

//Get parent
MutableIssue issue = issue;
MutableIssue parentIssue = issue.getParentObject();

MutableIssue subtaskWithMaxDueDate = returnMostFutureDate(parentIssue, issue);

//Get max due date of all subtasks and set the parent's due date
if( (subtaskWithMaxDueDate.getDueDate() != null) && !(subtaskWithMaxDueDate.getDueDate().equals(parentIssue.getDueDate()))) {    
def dateToSet = subtaskWithMaxDueDate.dueDate.format("d/MMM/yy");
    updateDueDate(parentIssue, dateToSet);
log.info("Updated parent issue ${parentIssue} due date");
}

def
returnMostFutureDate(def parentIssue, def currentIssue) {
issueWithLatestDate = currentIssue;
    for(Issue subtask : parentIssue.getSubTaskObjects()) {        
if( (subtask.getDueDate() != null) && (subtask.getDueDate().after(issueWithLatestDate.getDueDate()))) {            
issueWithLatestDate
= subtask;
     }
}
return issueWithLatestDate;
}

def
updateDueDate (def issue, def dueDateParam) {
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
issueInputParameters
.with { dueDate = dueDateParam }

def
validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)

assert !validationResult.errorCollection.hasAnyErrors()
issueService
.update(user, validationResult)
log
.debug "Subtask ${issue.key} updated"
}

 

0 votes
Vasiliy Zverev
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.
January 12, 2016

Jeon, do not give up so fast. 

I can help you to write a script (it is simple). But to run it you need a ScriptRunner. Is it possible to use ScriptRunner plugin for you (free for JIRA 6)?

Sangjun Jeon January 12, 2016

Yes. Possible! Thank you so much for your help in advance.

0 votes
Sangjun Jeon January 12, 2016

Thanks.But I am not professional to make a script code. I'd like to know the Jira base function. Hm... Anyway thank for your help.

0 votes
Phill Fox
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 11, 2016

To achieve this you will need to add a script plugin such as ScriptRunner which can take your change and review the parent task due date for differences.

Sangjun Jeon January 12, 2016

Thanks.But I am not professional to make a script code. I'd like to know the Jira base function. Hm... Anyway thank for your help.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 12, 2016

There is no "base function", you need to find/write code to do it. ScriptRunner makes it easy, but it's still coding.

Artur Martins March 7, 2017

i'm trying to make something like this, but in my case I need a script just to change the subtask due date when I change my parent issue due date, I need the same date...How can I do?

0 votes
Vasiliy Zverev
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.
January 11, 2016

You need some script for it. Is it acceptable solution for you?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events