Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner Listener: How do you trigger 'Create a sub-task' based on checkbox value?

Diana
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 Champions.
September 25, 2023

Similar to this question, but I'm running into an error where the auto creating subtask will only create the last option in the checkbox list, and not all options selected after an edit.

Example:

Checkbox field at the parent issue after 1 edit:

  • Option 1 - checked
  • Option 2
  • Option 3 - checked

Expected Results, subtask's summary as:

  • Subtask: Option 1
  • Subtask: Option 3

Actual Results:

  • Subtask: Option 3

In the listener script, I set Event trigger to Issue Created and Issue Updated. Under Conditions I use:

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.customfields.option.Option

def cf = customFieldManager.getCustomFieldObjectsByName("Checkbox")

def cfValue = cf.getAt(0).getValue(issue)

def subtaskSummaries = (cf as Collection<Option>)*.value

if(issue.issueType.name == "Parent" && cfValue != null){

    if(!issue.getSubTaskObjects()*.summary.equals(subtaskSummaries)){

        return true

    }

}
Target Issue Type = Subtask
Subtask summary left blank, no fields copied.
Under Additional issue actions I use:
def cf = customFieldManager.getCustomFieldObjectsByName("Checkbox").getAt(0)

def cfValue = sourceIssue.getCustomFieldValue(cf)

def subtaskSummaries = (cf as Collection<Option>)*.value

subtaskSummaries.each {

    if(!sourceIssue.getSubTaskObjects()*.summary.contains(it)){

        issue.summary = "Subtask: " + it

    }

}
Any suggestions why the script skips Subtask: Option 1?  

1 answer

0 votes
Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 8, 2018

Hello Jon,

For your use case, I think that sub-tasks would be a good feature since you can add them as shipments while tasks are the Contract Request itself.

Also, I believe that the import using CSV (Excel) can be useful to create the sub-tasks once many fields are with the same value:

Creating issues using the CSV importer

Jon
Contributor
October 9, 2018

thanks for this idea. is there a way to when making the issue (in this case its a contract) to make a certain number of sub tasks? for example, I would make a contract, and want to make 50 sub tasks. the fields in these subtasks would be supplied at that time or at a later date but the main thing is that the subtasks are created at that time indicating that there are 50 loads (or sub tasks) on this contract for us to pick up. 

Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 9, 2018

Hello Jon,

I would recommend you to use the CSV import option provided before if you are looking for a free option, however, if you are looking for a more practical option, there are a lot of plugins that you can use to achieve that goal.

The one I recommend you is the Automation Lite for JIRA Cloud, where you can create a simple rule to automatically create sub-tasks when creating a new issue:

Screen Shot 2018-10-09 at 18.03.51.png

Jon
Contributor
October 10, 2018

thanks for this idea. is there a way to automate the number of sub tasks it makes? and have the number of sub tasks created contingent on a custom field in the issue (i.e. "Number of loads")? 

Jon
Contributor
October 15, 2018

hi petterson,

 

just wanted to check if this idea that you gave can incorporate a function on how many sub tasks to create based on a field in the parent issue " Number of Loads" which can be anywhere from 1-100?

Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 15, 2018

Hello Jon,

Unfortunately, I think it's not possible to create multiple sub-tasks based on a Custom field number using Automation for JIRA.

I think the only possible way to do it using Automation for JIRA is by configuring a single action for each sub-task created.

Also, if you are familiar to Groovy Script, you can use the Add-on Scriptrunner and follow the instructions on the question below to configure your script:

How to Create multiple Sub-tasks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events