How to create subtask depending on Select List (multiple choices)
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
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.
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.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.customfields.manager.OptionsManagerdef 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.valuedef 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
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)
Yes, of course you need to change 10xxx with your custromfield id, like: customfield_10406.
Hi again @Mobily Monks
Have you achieved? If it helped, please accept the answer so that other community users might see the solution.
Thanks
It looks like you're new here. Sign in or register to get started.