Script Runner - Create Sub-task conditional of Project

We are using Script Runner to create sub-tasks on transition. How do we set up the post-function so that sub-tasks are only created for specific projects, and not for every project?


Project A transitions a Story to "accepted" and 3 sub-tasks are auto created

Project B transitions a Story to "accepted" and no sub-tasks are created

1 answer

1 accepted

2 votes

You could use different scripts by having different workflows, or you could stick an "if" statement into the script to check which project you are currently in.

Nic, I would like to add an "if" statement but can not find the syntax for getting the project name and/or id. The post function is run against the Accepted transition - == 'Accepted'

I have a similar condition using the built-in script for creating subtasks on the Create transition, it's: == 'Story' && issue.getProjectObject().getKey() != ‘Project B' So, here, if it's a story and not Project B, the sub-task is created. I have two of these post functions defined, one per sub-task.

Jeremy, What do you mean by you have two of these post functions defined, one per sub-task? We are not having any luck using the script you gave us. Having no issues using script and sub-task are created, but need the ability to make sure it's only for projects that we have in the script, since there will be projects on the workflow that will not use this function. Thanks

I mean my workflow's "Create" transition has two "Post Functions", both of which are of type "Script workflow function : Create a sub-task". Each of them has the criteria I listed above, replacing "Project B" with the one project I don't create sub-tasks for. For you, you'd need 3 post functions, unless you are creating them in a single custom script; at that point, my example condition will need to be integrated into your script as an explicit "if" statement.

Thank you Jeremy! This worked perfectly - == 'Story' && issue.getProjectObject().getKey() != ‘Project B'

Jeremy, What if we had two or more projects that would be running the same script?

Well, it depends on if you want to create subtasks for them or not. Say you have 4 projects, and you want subtasks for 3 out of 4, you use the same condition as above, where it's: == 'Story' && issue.getProjectObject().getKey() != ‘Project 4' If you only want subtasks for project 2, it's: == 'Story' && issue.getProjectObject().getKey() == ‘Project 2' And if you want subtasks for 1 and 4, you could use either: == 'Story' && issue.getProjectObject().getKey() != ‘Project 2' && issue.getProjectObject().getKey() != ‘Project 3' or: == 'Story' && (issue.getProjectObject().getKey() == ‘Project 1' || issue.getProjectObject().getKey() != ‘Project 4')

Thanks, it works great now! :)

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

239 views 0 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot