How to create subtask depending on Select List (multiple choices)

Mobily Monks September 13, 2019

How to create subtask depending on Select List (multiple choices)

2 answers

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 16, 2019

I tried to write the script as below. I did not test it, I just wrote here in the answer section.

But, it might be a good guide to start. 

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

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
def constantManager = ComponentAccessor.getConstantsManager()

CustomField customField = customFieldManager.getCustomFieldObject("customfield_10xxx")
List<Option> options = issue.getCustomFieldValue(customField)


options.each {
// these are the selected options, you can use these option values in this loop
def optionValue = it.value
def optionId = it.optionId
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setAssigneeId(issue.assigneeId)
newSubTask.setSummary("sub task summary")
newSubTask.setParentObject(issue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id) // or just give the issueTypeId for sub-task

// set any custom field if you want
newSubTask.setCustomFieldValue(cf, value)
def newIssueParams = ["issue" : newSubTask] as Map<String,Object>

issueManager.createIssueObject(authorUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, authorUser)

log.info "Issue with summary ${newSubTask.summary} created"
}

Let me know if you have any issues

Cheers

Tuncay Senturk

Mobily Monks September 17, 2019

I have to update customfield_10xxx with the actual value 10406 and this code is good to go. Please confirm.

Or Do I have to update  customField  with the  custom Field Name  and options with any value? 

 

CustomField customField = customFieldManager.getCustomFieldObject("customfield_10xxx")
List<Option> options = issue.getCustomFieldValue(customField)

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 17, 2019

Yes, of course you need to change 10xxx with your custromfield id, like: customfield_10406. 

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 6, 2019

Hi again @Mobily Monks 

Have you achieved? If it helped, please accept the answer so that other community users might see the solution.

Thanks

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 14, 2019

Hello @Mobily Monks 

Can you please clarify the question?

What actually do you want to do? Automatically create subtasks depending on the select list values? If yes, when do you want to create? In create transition's post function?

Are you looking for a solution via code (e.g. Script runner) or do you want to achieve that with Jira and/or plugins?

Best

Mobily Monks September 16, 2019

Yes, we have a set of subtasks which we would like them to be automatically created when select list values are selected.

I am looking for a code( Script runner) solution and NOT apparently with plugins.

Suggest an answer

Log in or Sign up to answer