Create Sub Tasks based Multi Select Custom Field

Hi,

In create issue Screen, i have a multi select custom field, which has below options

Options: Reviewer 1, Reviewer 2, Reviewer 3, Reviewer 4 ...

User can be able to choose/tick as many options he wanted,

like if user selected/tick: Reviewer 1, Reviewer 4 - then i need to create sub tasks and assign it to selected Users from Multi select custome field

Sub Task 1:

1. Assign to Reviewer 1

2. Copy Summary from Parent Issue

Sub Task 2:

1. Assign to Reviewer 4

2. Copy Summary from Parent Issue

Your help is appreciated

4 answers

You can use Jamie Echlin's script runner plugin. You might find the example code here helpful

https://jamieechlin.atlassian.net/wiki/display/GRV/Post+Functions#PostFunctions-Cloneissuewithdependencylink

Thanks for the response Bhushan, script in the link you provided is to create sub tasks and copy parent values to subtasks which i did already, but now i want to read/get selected values from multi select custom field and set sub tasks assignee based on it

Hi Govardan and Bhushan I have a similar requirement, when a custom field is set to 'Yes', need to create a subtask and assign to a user id I modified below script like this, and i am getting error msg, can you pls help with this. {code} cfDocReqd = customFieldManager.getCustomFieldObjectByName("Is Documentation (TD) Required?") cfvalue = issue.getCustomFieldValue(cfDocReqd); if (cfvalue= "Yes") { issueObject = issueFactory.getIssue() issueObject.setProject(issue.getProject()) issueObject.setIssueTypeId("10538") issueObject.setParentId(issue.getId()) issueObject.setSummary(issue.getSummary()) subTask = issueManager.createIssue(authenticationContext.getUser(), issueObject) subTaskManager.createSubTaskIssueLink(issue.getGenericValue(), subTask, authenticationContext.getUser()) } {code} Error i am getting : Script function failed on issue: : 101, file: <inline script> groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script8 at Script8.run(Script8.groovy:1) I am using this as post function to test this, once this is good, i want to use this as custom listener.

Are you using a multi-user select field?

Yes i am using Multi User Picker field

I was able to achieve this with below code, in case any one needed

cfStewards = customFieldManager.getCustomFieldObjectByName("Stewards")

Collection<User> users= (Collection) issue.getCustomFieldValue(cfStewards);

if(users != null)
{
for(i in 0..users.size()-1)
{
Object AssigneeValue = users.get(i).getName();

issueObject = issueFactory.getIssue()
issueObject.setProject(issue.getProject())
issueObject.setIssueTypeId("10")
issueObject.setParentId(issue.getId())

issueObject.setSummary(issue.getSummary())
issueObject.setAssigneeId(AssigneeValue)

subTask = issueManager.createIssue(authenticationContext.getUser(), issueObject)
subTaskManager.createSubTaskIssueLink(issue.getGenericValue(), subTask, authenticationContext.getUser())
i++
}

}

Do you add this to the post function after you have the field filled in with the users?

is "Stewards" the name of your field?

Anything else I would need to set to customize it for my setup?

Yes, you have to add it to the post funtion, this will run after you filled in users.

In order to work for you, you need to set correct sub task issue type id..

issueObject.setIssueTypeId("10") --- check this ID in your database for correct sub task issue type id

Hi, In create issue Screen, i have a multi select custom field, which has below options Options: Reviewer 1, Reviewer 2, Reviewer 3, Reviewer 4 ... User can be able to choose/tick as many options he wanted, like if user selected/tick: Reviewer 1, Reviewer 4 - then i need to create sub tasks and assign it to selected Users from Multi select custome field Sub Task 1: 1. Assign to Reviewer 1 2. Copy Summary from Parent Issue Sub Task 2: 1. Assign to Reviewer 4 2. Copy Summary from Parent Issue Your help is appreciated

is it work for above requirement

I have a number field. based number I want create subtask. if I enter 5 then I want to create 5 subtasks. if I enter 10 then I want to create 5 subtasks Please help me on same

Hi Mallikarjuna, Have you created Number field? If Yes, you can loop thru your custom number field and create subtasks based on number selected you should be able to use above code have you tried with above example?

yes I created number field and tried above code. but not working above code can I write this code in postfunction or listener? what listener can I use? for ex Create a subtask or fast track transition.....

any one can help me on above requirement

Hi Govardhan can u give me the Import class for above code .

Here are the imports i have used import com.atlassian.jira.issue.Issue import com.atlassian.jira.util.ImportUtils import com.atlassian.jira.workflow.WorkflowTransitionUtil; import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl; import com.atlassian.jira.util.JiraUtils; import java.lang.Boolean; whats the error you are getting? when you say not working.. whats your issue?

r u woking above code on fasttrack transition? or any other post function. how can i test my code is working or not i am new to jira scripting

below is my coding import com.atlassian.jira.issue.Issue import com.atlassian.jira.util.ImportUtils import com.atlassian.jira.workflow.WorkflowTransitionUtil; import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl; import com.atlassian.jira.util.JiraUtils; import java.lang.Boolean; cfLic = customFieldManager.getCustomFieldObjectByName("Number of Licenses") Collection<User> users= (Collection) issue.getCustomFieldValue(cfLic); if(users != null) { for(i in 0..users.size()-1) { Object AssigneeValue = users.get(i).getName(); issueObject = issueFactory.getIssue() issueObject.setProject(issue.getProject()) issueObject.setIssueTypeId("10417") issueObject.setParentId(issue.getId()) issueObject.setSummary(issue.getSummary()) issueObject.setAssigneeId(AssigneeValue) subTask = issueManager.createIssue(authenticationContext.getUser(), issueObject) subTaskManager.createSubTaskIssueLink(issue.getGenericValue(), subTask, authenticationContext.getUser()) i++ } }

my subtask issue type id is :10417

hi govardhan please help me on same

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

232 views 1 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you