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
Answer accepted

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 Sign up to answer
Community showcase
Posted Oct 09, 2018 in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

393 views 6 0
Join discussion

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