Script runner: creating sub-tasks based on checkbox field

Jose Jimenez August 3, 2016

Hi guys, hope you are doing great.

Here's what i'm trying to do: I have an issue parent with a checkbox custom field. After creating the issue, I would like to automatically create as many sub-tasks as options are marked on the checkbox.

For example, let's suppose the options of the checkbox field are:

  • A
  • B
  • C
  • D

While creating the parent issue I check options B and D. Right in the create transition, via post-function, I would like to automatically create two sub-task, with summary "Subtask B" and "Subtask D" for example.

 

Any clues? I'm working on JIRA 6.0

 

Thank you in advance for your help.

 

4 answers

1 accepted

2 votes
Answer accepted
Tarun Sapra
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 3, 2016

Hi Jose,

 

In the script-runner post-function there is a built-in postfunction to create a sub-task based on a condition.

 

Thus you can add 2 post-functions one for each sub-task and in the built-in post-function for sub-task creation you can check whats the value of the checkbox and if the value of the checkbox is what you want only then the subtask would be created.

Here's how you can check the checkbox value, this snippet can be put in the "condition" code block of the built-in script to create subtask.

cfValues['Reset Type']*.value.contains("Citrix")

https://answers.atlassian.com/questions/124728

Jose Jimenez August 12, 2016

Thank you so much! It worked. smile

 

Best.

Deleted user February 15, 2018

Hello @Jose Jimenez @Tarun Sapra ,

 

Working for server. Same code is not working in cloud.  Can you provide the code for JIRA cloud?

 

Thanks,

Swathi

Suhail Wani October 25, 2018

Hi @Tarun Sapra

 

I also tried this code on Jira cloud but it's not working. It seems this stuff is not supported in cloud. Can you please confirm if there is a script for cloud.

I am also trying to achieve this using JMWE. However, the condition does not allow me to add a condition for custom field.

 

Thanks

Suhail Wani

Akbar N May 6, 2019

@Tarun Sapra @Tarun Sapra 

Hi Tarun, How i can handle the creation of sub-task automatically? Say for one issues user will selects only option A but for another Issue user selects Option A, B and C. In the second case it needs to create three sub-task.  Is that a way i can achieve this without creating pre-defined set of Post functions rather handling it automatically based on the number of values selected?

 

Thanks in Advance.

0 votes
Akbar N May 7, 2019

@Tarun Sapra 

Thanks for the info. Yaah i see that as a possibility to address my scenario. On related to this question, we are trying to use multi-select dropdown with 50 values as options to choose by the selection, in this case i have to create 50 post function scenarios to address my use case correct?

 Is this a only option and will have any performance impact as for creating every issue, there are 50 post functions are getting validated etc? 

Is there any other option to address it? Thanks in Advance.

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2019

Hello @Akbar N 

If the number of options is so high (50!) then don't use the post-function approach. Instead create a custom listener which should be triggered and in that listener check the number of values selected for the multi-select field and for each value create a sub-tasks using Java API in a loop.

https://developer.atlassian.com/server/jira/platform/performing-issue-operations/

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 7, 2019

Hello @Akbar N 

For your use-case

"Say for one issues user will selects only option A but for another Issue user selects Option A, B and C. In the second case it needs to create three sub-task. "

You can create multiple post-functions for creation of sub-tasks and each sub-task post-fcuntion execution depends of the condition if the relevant checkbox is selected or not.

And if all the checkboxes are selected then all the post-functions will execute resulting in multiple sub-tasks being created as a result of multiple options being selected for the checkbox custom field.

0 votes
Suhail Wani October 30, 2018

@[deleted] @Tarun Sapra

 

I sorted this out.Below is the code for Jira cloud to add the condition in the create subtask post function.

 

((List)issue.fields.customfield_<IDHere>)?.collect { it.value }?.any { it == '<OptionValueHere>' }

 

Thanks

Suggest an answer

Log in or Sign up to answer