ScriptRunner how to create a sub-task for an Issue with relevant information

Roberto L
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.
August 23, 2017

Hello Community,

I am in the process of figuering out how to create a sub-task for an issue when a specific condition is met.

My use-case is:

When a user updates the custom field "Requires Attention" with the value of "Yes" I would like to create a sub-task under this issue which has the name of the Issue plus the letters "RA". I want this sub-task to be created only when that custom field is triggered and the issue is updated, I do not wish this sub-task to be created when the issue in general is updated. If the user de-selects the "Requires Attention" field and then selects it again it should create a new sub-task with the relevant information.

I was thinking about utilizing a Behaviour that checks for a specific change in value in one of the fields. When such a field changes I would like to create a sub-task under that issue. I also would like that sub-task to have certain information copied from its parent Issue. I am unsure what the code to achieve this would look like.

It is worthwhile noting that I utilized the Listener Create Sub-Task Script offered by ScriptRunner and it initially worked, but upon further utiliziation it did not quite meet the criterias I require.

For example, I want this script to run whenever a user modifies only one value ( a custom field) in the Issue Update form. The Listener can only listen to when an issue is updated in general. So it would run everytime a user updated an issue, therefore creating many sub-tasks which arent needed even though I wrote a conditional that would check if a certain custom field had a certain value. This failed because if the issue had its custom field value set already and the user updated an issue (perhaps updated the description), the script would run (because the custom field value was set to value defined in the condition) and create a new sub-task, which is something not desired.

Furthermore, I noticed the Listener had the Subtask Action option, but that did not help because if for somereason the sub-task was in the "Done" stage and then a user updated the issue it would re-open the sub-task even though there is no need for it to be re-opened. Perhaps, there is a way to utilize this Built-in Script, if there is please advise me as to how I can levarage it for the functionality I require.

 

Is there anyway this functionality can be implemented in Jira?
I appreciate any guidance on this,

-Roberto

1 answer

1 accepted

1 vote
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.
August 23, 2017

You still need a listener, but you need to be more clever about the code you put as a condition.

You've put in "if custom field = X, then execute".  What you need is a set of rules:

  • If custom field = X
  • and the event you caught says the changes included a change of value for the custom field
  • and if there are no matching sub-tasks already in existence

I'm not sure the rules can be built in to the stock listener, I suspect you will need to write your own listener script that includes them at the top.

Roberto L
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.
August 23, 2017

Hey @Nic Brough -Adaptavist-,

My current condition is the following:

'requires attention' in cfValues['Security Impact']*.value

The custom field is of type checkbox.

Would you know how to add those rules. Most importantly how to check if the event caught says that my custom field value has been changed. I am just very lost when it comes to how to put code into conditions.

If this cant be done in a condition, in a custom Listener how do you check for:

  • and the event you caught says the changes included a change of value for the custom field
  • and if there are no matching sub-tasks already in existence

And how do you create sub-tasks through code?

-Roberto

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events