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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

duplicate task based on multiple selection in custom field

Hi All,

I'm taking my first steps in script runner for jira, and though I've read (and tried) a lot questions & answers  here , I'm still facing issues, so here goes:

I need to create a few tasks based on values of multi selection customized field, here are the details:

I have a custom field  " Office" from type multi-selection list, let's say OfficeA, OfficeB, OfficeC.

When a task is created I need to create separate tasks,  according to the selected values in the "Office" field. Each  of those tasks must have the same field values as the original one, but Office" which needs to be marked with a single value which was selected.

For example: if selected values are OfficeA, OfficeB the result will be 2 (almost) identical tasks, the only difference is that one of them will be Office=OfficeA and the other Office = OfficeB.


After the creation of the additional tasks - I don't care about the original task, if it helps I can use it as one of the "new" tasks (with removal of redundant "Office" values)

No need in coping comments, links, etc. only the fields.


We use Jira server 8.5.6 , and script runner 6.16.0, I added a post function in the "create" transition which uses the "clone an issue, and links", currently I have in condition 'OfficeA' in cfValues['Office']. Value, but I don't know how to fill the "Office" value for the cloned task since it will also clone another task in its create transition L


A few question here:

  • Is there a way to clone all required tasks us a single post functions or should I add post function per optional value of "Office"?
  • How do I avoid the internal loop of  create transition (in other words – how to write the condition such it will duplicate only the original task?)
  • I also wanted to assign specific user for every "Office" value, I tried to use issue.setAssigneeId('OfficeA_user') but that didn't work , I understood that there was an issue with the set function and I should use the update but couldn't understand hoe to use it (nor the difference between them)



Any assistance will be appreciated J




1 answer

0 votes
scott_boisvert Community Leader Feb 09, 2021


I actually just did something similar, rather than a post function, I did it as a listener, as I need it to create tasks every time the checkbox field is updated. I would suggest that rather than using the same issue type, you make the new tasks subtasks of the original task (which is what I did). I have an issue type called Application Change Request and subtasks called Deployment Tasks. I have a field called Deployment Profiles that when updated is read and a Deployment Task created for each option selected. Below is my script for reference, it might help you in what you're trying to accomplish:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.FieldManager
import com.atlassian.jira.issue.fields.screen.FieldScreenManager
import com.atlassian.jira.issue.fields.screen.FieldScreenLayoutItem
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.version.Version
import java.sql.Timestamp

def im = ComponentAccessor.getIssueManager()
//def parentIssue = im.getIssueObject("DIGCLM-91") //for debugging
MutableIssue parentIssue = event.issue as MutableIssue

if (parentIssue.getIssueType().name == "Application Change Request" && event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Deployment Profile(s)"})
def cfm = ComponentAccessor.getCustomFieldManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def stm = ComponentAccessor.getSubTaskManager()
def cm = ComponentAccessor.getConstantsManager()
def fm = ComponentAccessor.getFieldManager()
def fsm = ComponentAccessor.getFieldScreenManager()

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def deploymentProfiles = cfm.getCustomFieldObjectsByName("Deployment Profile(s)")
def parentDeploymentProfiles = parentIssue.getCustomFieldValue(deploymentProfiles[0]) as List
def subTasks = parentIssue.getSubTaskObjects()

parentDeploymentProfiles.each { profile ->

boolean subtaskExists = false

subTasks.each { subtask ->

if (subtask.getSummary() == "Deployment Profile: " + profile as String)
subtaskExists = true

if (!subtaskExists)
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Deployment Profile: " + profile as String)

def screen = fsm.getFieldScreen(13002 as Long)
def tab = screen.getTab(0)
def fields = fsm.getFieldScreenLayoutItems(tab)

fields.each { fieldLYOI ->

def field = fm.getField(fieldLYOI.getFieldId())
if (fm.isCustomField(field))
def cf = fm.getCustomField(fieldLYOI.getFieldId())
newSubTask.setCustomFieldValue(cf, parentIssue.getCustomFieldValue(cf))

it.getName() == "Deployment Task"

def newIssueParams = ["issue" : newSubTask] as Map<String,Object>
im.createIssueObject(currentUser, newIssueParams)
stm.createSubTaskIssueLink(parentIssue as Issue, newSubTask as Issue, currentUser)
scott_boisvert Community Leader Feb 09, 2021

I probably should put more comments in there... lol

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,184 views 8 28
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you