Forums

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

Trouble getting scriptrunner to set due date for all subtasks if parent is updated

Tommy Bananas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 3, 2019

I'm having some difficulty getting the duedate set on the subtasks using a customer listener on scriptrunner.  I was simply using the setduedate function but couldn't get it to write.  Googling led me down a lot of odd paths from trying to use store (per Jira instructions that seem outdated) to adding the four lines embedded in the subtasks.each loop.  Would love a hand or some guidance.

Note: Currently get an error on the updateValue function call.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.type.EventDispatchOption
log.setLevel(org.apache.log4j.Level.INFO)
log.info("start");

IssueManager issueManager = ComponentAccessor.getIssueManager();
// Check if Due Date changed
if (event.getChangeLog().getRelated("ChildChangeItem").find {it.field == "duedate"})
{
def Due = event.issue.dueDate
log.info ("Due Date changed")
def subtasks = event.issue.getSubTaskObjects()
log.info ("${Arrays.toString(subtasks)}")
//log.info ("${subtasks.length} subtasks exist")
subtasks.each {
Issue issue = issueManager.getIssueObject(it.getKey())
MutableIssue mutableIssue = (MutableIssue)issue;
mutableIssue.setDueDate(Due);
issueManager.updateValue("Time", mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false);
log.info ("Date Date for ${mutableIssue} changed to ${Due}. ")
}
}
else {
log.info("Due Date not changed. ${event.getChangeLog().getRelated("ChildChangeItem")}");
}

2 answers

0 votes
PD Sheehan
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.
April 4, 2019

I think the updateIssue method is the correct one, but I wonder if you have the correct  arguments:

https://docs.atlassian.com/software/jira/docs/api/7.8.2/com/atlassian/jira/issue/IssueManager.html#updateIssue-com.atlassian.jira.user.ApplicationUser-com.atlassian.jira.issue.MutableIssue-com.atlassian.jira.event.type.EventDispatchOption-boolean-

Your code has:

issueManager.updateValue("Time", mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false);

 You need an application user instead of "Time".

You can use the current logged in user with:

ComponentAccessor.jiraAuthenticationContext.loggedInUser

If Time is actually the user that you want to own the change, then you can use this:

ComponentAccessor.userManager.getUserByName('time')

 Also, as mentioned by @Antoine Berry , remember to re-index your subtasks. Jira won't do it for you.

0 votes
Antoine Berry
Community Champion
April 4, 2019

Hi,

I have had success with this for setting the due date on an already created issue : 

issue.setDueDate(dueDate)
def
issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
issue.store()
issueIndexingService.reIndex(issue)

 and you could get rid of the updateValue. 

Antoine

Suggest an answer

Log in or Sign up to answer