You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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:
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.
I think you should try to write a script yourself first. You can find info on how to create subtasks using scriptrunner here:
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"
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kindly read my article here
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"]))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.