Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Basically I am trying to take the required parent due date, subtract 14 days from it and apply it to my subtask's due date field.
Currently it is setting the subtask due date as the created minus 14 days which is not what I want.
I want to set the parent to Apr/20/20 and then the subtask automatically, upon creation through a transition, sets its own due date to Apr/06/20.
The code I have right now in my subtask additional issue actions is:
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import java.sql.Timestamp;
MutableIssue myIssue = issue;
Calendar dueDate = Calendar.getInstance();
myIssue.setDueDate(new Timestamp((new Date() - 14).time));
Any help would be much appreciated
Hi
If I understand you correctly you need listener that fires when issue is updated
In listener you can
a) check if this is parent issue.
b) get parent issue due date
c) get all subtasks of this issue
d) update due date of each subtask.
Something like this:
Issue currentIssue = event.issue;
if(!(currentIssue.isSubTask())){
//this is parent issue
//get due date
Timestamp dueDateVal = currentIssue.getDueDate();
//then you can update due date of this issue
//review all subtasks and perform any operations with them
//e.g. update parent issue
MutableIssue issueToUpdate = (MutableIssue) event.issue
issueToUpdate.setDueDate(Timestamp '<your new dueDate value for parent issue>');
//get collection of subtasks
Collection<Issue> subTasksCol = currentIssue.getSubTaskObjects();
//iterate colleaction with subtasks and update duedate of each of them
for (Issue subTaskEl : subTasksCol) {
MutableIssue subTaskM = (MutableIssue) subTaskEl;
subTaskM.setDueDate(Timestamp '<your new dueDate value for subtasks>')
}
}
The parent due date will not be changed since it is required upon creation. So parent due date won't need to be updated. Upon transition of the parent to In Progress, the subtasks are all generated and need to have the parent due date set. I would prefer to use a post function for this, but I can try the listener and see if it throws any errors or gives me any issues.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tried to test and it won't run. I set up a custom listener to fire when the the "issue updated" event occurs. Did not run once. Maybe I'm misunderstanding where to place this?
Also the Timestamp code gives me an error so I tweaked it to follow my code posted above.
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import java.sql.Timestamp;
Issue currentIssue = event.issue;
if(!(currentIssue.isSubTask())){
//this is parent issue
//get due date
Timestamp dueDateVal = currentIssue.getDueDate();
//then you can update due date of this issue
//review all subtasks and perform any operations with them
//e.g. update parent issue
MutableIssue issueToUpdate = (MutableIssue) event.issue
issueToUpdate.setDueDate(new Timestamp((new Date() - 14).time));
//get collection of subtasks
Collection<Issue> subTasksCol = currentIssue.getSubTaskObjects();
//iterate colleaction with subtasks and update duedate of each of them
for (Issue subTaskEl : subTasksCol) {
MutableIssue subTaskM = (MutableIssue) subTaskEl;
subTaskM.setDueDate(new Timestamp((new Date() - 14).time));
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1. you need to put your custom listener here
Manage apps -> Script listeners
2. Try to enable logging
import org.apache.log4j.Logger
import org.apache.log4j.Level
import org.apache.log4j.Category
//for log levels
Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.INFO)
log.info("start logging ");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That is where I put my custom listener. Also I put the logging code in there, but I doubt its going to tell me anything since this hasn't actually run. Even though I have updated the test parent by transitioning it, the listener doesn't change anything.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmmm.... if this listener was not executed at all, looks like event was not fired or project scope is incorrect.
Could you create new custom listener with following parameters
a) change project scope to "All projects"
b) add new import row in the top
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
c) delete all code except import rows and log code
d) initiate "issue updated" event
e) see result - there is a "History" section
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay so made the test listener and that ran, but didn't give any failures or anything I could really gleam from it. And then out of curiosity I updated the parent due date by one day and the other listener ran, but didn't change any of the due dates in the subtasks.
I would think the transition of the parent to In progress from open would count as an issue updated event, but apparently not.
This is all it gave me in their history sections:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Yuu wrote "other listener ran, but didn't change any of the due dates in the subtasks."
If listener was executed it means that event was fired.
You can enable logging (see my previous comment), then execute your listener and check all values you need.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In addition:
Try to use issueManager.updateIssue method together with setDuedate method
See this articles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Maybe my original explanation is confusing. I want to take the parent's dueDate (i.e. Apr/20/20) apply it to the subtasks, but subtract a certain amount of days, say 14, so the subtasks due date would be (Apr/06/20).
I think a listener would work in this case but your suggestions were to use other date picker type fields and base it off of that. If I need to make another date picker field for this to work I will but I thought maybe something like this may work as well? https://community.atlassian.com/t5/Jira-questions/Custom-update-listener-to-set-subtask-s-fix-version/qaq-p/591808 So instead of fixVersions I would use dueDate
@Nic Brough -Adaptavist-i know you in the past suggested how to set a duedate based on creation date minus a certain amount of days.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.