Can someone help with the groovy script to conditionally create a sub-task when a Story moves from one project to another? I looking to use ScriptRunner Move Listener for this.
Use Case: When a Story moves out of/from the project key "CAP" to any other project, check if sub-task (Code Review) has been created and if not, create sub-task (Code Review) which is just a standard sub-task with "Code Review" as its summary. We need to also consider if a Story is moving into project key "CAP", do not create sub-task (Code Review).
Appreciating your help and please let me know if additional details are needed.
Thanks!
With scriptrunner's script listener, you can use the built-in "create subtask" listener and configure it as follows:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
Issue eventIssue = issue
def projectsList = projects
def sourceProject
def newProject
if(projectsList[0] == eventIssue.getProjectObject().getKey()){
sourceProject = projectsList[1]
newProject = projectsList[0]
}
else{
sourceProject = projectsList[0]
newProject = projectsList[1]
}
log.info("Issue moved from ${sourceProject} to ${newProject}")
def subtasks = eventIssue.getSubTaskObjects()
def subTaskExists = subtasks.any {it.getSummary().toLowerCase().contains("code review")}
if(sourceProject == "CAP" && !subTaskExists)
{
return true
}
else {
return false
}
You can probably simplify it/clean it up.
All the rest, I left empty.
Hope this helps
Kind regards
Jorden
Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!
Help us plant more trees
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.