Forums

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

ScriptRunner | Move Listener | Create Sub-task | Conditionally

Luis Tellado April 11, 2022

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!

1 answer

0 votes
Jorden Van Bogaert
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 12, 2022

Hi @Luis Tellado 

With scriptrunner's script listener, you can use the built-in "create subtask" listener and configure it as follows:

  • Apply to the specific projects that you want the move event to create subtasks for (I included both source and destination projects as triggers)
  • Events: "Issue Moved"
  • Condition (based on your use case)
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.

  • target issue type --> choose the subtask type you want to use (needs to exist in the project)
  • Fields to copy --> as per your requirements

All the rest, I left empty.

Hope this helps
Kind regards
Jorden

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events