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
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, of course you need to change 10xxx with your custromfield id, like: customfield_10406.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Mobily Monks
Have you achieved? If it helped, please accept the answer so that other community users might see the solution.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.