Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,557,844
Community Members
 
Community Events
184
Community Groups

create mulitple subtasks from multiselect checkbox field

My issue create screen has a multi-select checkbox custom field. I would like a scriptrunner post-function that will:

a) create a sub-task for each option selected

b) use the name of the selected checkbox in the sub-task summary

 

Example:

My custom field is called: "colors"

The following options exist:

  • "blue"
  • "green" -> checked
  • "red" -> checked

 

Desired outcome from post-function: Create two sub-tasks with summary as follows:

1) "Subtask - green"

2) "Subtask - red"

I am using jira server 7.x and latest scriptrunner plugin.

1 answer

1 accepted

0 votes
Answer accepted
Alexey Matveev
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.
Mar 01, 2018

I think you should try to write a script yourself first. You can find info on how to create subtasks using scriptrunner here:

https://community.atlassian.com/t5/Jira-questions/How-to-Automatically-create-Sub-task-using-script-runner-post/qaq-p/400564

I created the following script which works.

However I have not figured out how to set a checkbox in the newly created sub-task as indicated in the code comment.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.manager.OptionsManager

import com.atlassian.jira.user.ApplicationUser

import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)

def constantManager = ComponentAccessor.getConstantsManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Issue parentIssue = issue

def customFieldManager = ComponentAccessor.customFieldManager
def cf = customFieldManager.getCustomFieldObject("customfield_10107")
def summariesList = (issue.getCustomFieldValue(cf) as Collection<Option>)*.value

summariesList.each {
if (!issue.getSubTaskObjects()*.summary.contains(it)) {
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setAssigneeId(parentIssue.assigneeId)
newSubTask.setSummary(it)
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Sub-task"}.id)

// I want to set a checkbox field in newly created sub task next


def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def cFM = ComponentAccessor.getCustomFieldManager()
def cff = customFieldManager.getCustomFieldObject("customfield_10107")
def fieldConfig = cff.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("${it.toString()}", null)
newSubTask.setCustomFieldValue(cf, [option])

def newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)

log.info "Issue with summary ${newSubTask.summary} created"
}
}
Alexey Matveev
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.
Mar 05, 2018

Kindly read my article here

https://community.atlassian.com/t5/Agile-articles/Three-ways-to-update-an-issue-in-Jira-Java-Api/ba-p/736585

You use the frist method in my article. You should get options for the field like this

def List<Option> getOptions(Issue issue, CustomField customField, List<String> optionList) {
    def config = customField.getRelevantConfig(issue)
    def options = ComponentAccessor.getOptionsManager().getOptions(config)
    def optionsToSelect = options.findAll { it.value in optionList }
}

and set the value like this

issue.setCustomFieldValue(checkbox_field, getOptions(issue, checkbox_field, ["option 1", "option 2"])) 

That worked. Thanks for your help.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events