Script Runner - Create Sub-task conditional of Project

Jeanne Howe
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.
November 10, 2015

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?

Example:

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
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 10, 2015

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.

Jeanne Howe
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.
November 11, 2015

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 - issue.status.name == 'Accepted'

Jeremy Gaudet
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.
November 11, 2015

I have a similar condition using the built-in script for creating subtasks on the Create transition, it's: issue.issueTypeObject.name == '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.

Davor Fisher November 11, 2015

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 issue.status.name 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

Jeremy Gaudet
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.
November 11, 2015

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.

Jeanne Howe
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.
November 11, 2015

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

Davor Fisher November 12, 2015

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

Jeremy Gaudet
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.
November 12, 2015

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: issue.issueTypeObject.name == 'Story' && issue.getProjectObject().getKey() != ‘Project 4' If you only want subtasks for project 2, it's: issue.issueTypeObject.name == 'Story' && issue.getProjectObject().getKey() == ‘Project 2' And if you want subtasks for 1 and 4, you could use either: issue.issueTypeObject.name == 'Story' && issue.getProjectObject().getKey() != ‘Project 2' && issue.getProjectObject().getKey() != ‘Project 3' or: issue.issueTypeObject.name == 'Story' && (issue.getProjectObject().getKey() == ‘Project 1' || issue.getProjectObject().getKey() != ‘Project 4')

Davor Fisher November 13, 2015

Thanks, it works great now! :)

Suggest an answer

Log in or Sign up to answer