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")}");
}
I think the updateIssue method is the correct one, but I wonder if you have the correct arguments:
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.
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
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.