Is it possible to create sub-tasks based on custom field value during 'Edit' issue?

After the issue is created, during 'edit' issue if the custom field value is updated, I want the sub-tasks to be created. Is this possible?

3 answers

1 accepted

I think you should create a listener that catches the event of editing the custom field value.

Kostas,

Do you have an idea on how to create a listener? I have tried using this but receiving erros:

com.atlassian.jira.event.issue.IssueEvent

Thanks,

Yeah for "edit" operations you will need a listener... can you be more specific about the error you are getting.

You could use a Script Listeners -> Create sub-task, then specify a condition which checks if the value of your field has been newly changed to the value you care about.

My custom field is a date field. When user chooses a date for this field (which will not be chosen while creating /transitioning a ticket, ), sub-tasks should be triggered. If I have to use Script listeners, What are the steps that I need to follow?

Thanks,

I have tried to create a normal listener from Administration > Listeners the follwoing way.

Name: Listener for issue event

Class: com.atlassian.jira.event.issue.IssueEvent

Error: Exception loading class: [com.atlassian.jira.event.issue.IssueEvent doesn't have any satisfiable constructors. Unsatisfiable dependencies: [[interface com.atlassian.jira.issue.Issue, interface java.util.Map, interface com.atlassian.crowd.embedded.api.User, class java.lang.Long], [interface com.atlassian.jira.issue.Issue, interface com.atlassian.crowd.embedded.api.User, interface com.atlassian.jira.issue.comments.Comment, interface com.atlassian.jira.issue.worklog.Worklog, class org.ofbiz.core.entity.GenericValue, interface java.util.Map, class java.lang.Long], [interface com.atlassian.jira.issue.Issue, interface com.atlassian.crowd.embedded.api.User, interface com.atlassian.jira.issue.comments.Comment, interface com.atlassian.jira.issue.worklog.Worklog, class org.ofbiz.core.entity.GenericValue, interface java.util.Map, class java.lang.Long, boolean], [interface com.atlassian.jira.issue.Issue, interface java.util.Map, interface com.atlassian.crowd.embedded.api.User, class java.lang.Long, boolean], [interface com.atlassian.jira.issue.Issue, interface com.atlassian.crowd.embedded.api.User, interface com.atlassian.jira.issue.comments.Comment, interface com.atlassian.jira.issue.worklog.Worklog, class org.ofbiz.core.entity.GenericValue, interface java.util.Map, class java.lang.Long, boolean, boolean]]].


Name: Listener for issue event

Class: com.atlassian.jira.event.issue.IssueEventListener

Error:
Exception loading class: [Bad Access: 'com.atlassian.jira.event.issue.IssueEventListener' is not instantiable].

Hey Vishali,

as Jamie said in the above comment you have to create a scripted listener using groovyrunner.

Script Listeneners > Create Sub-task

Kostas,

As the custom field value will either have a date or null value, what should I set the condition to be?

Thanks,

Hey Vishali,

what's the type of custom field that you are editing and fires the issue creation?

If it's a date custom field, i think condition should be something like:

cfValues['date_field'] == null || cfValues['date_field'] != null

If it's not a date field i think there should be a regex that validates if the entered values have date like format.

Hope that helps

Cheers

Kostas,

Thank you for your reply. I was busy with one of the releases and couldn't respond faster. Could you please provide me detailed steps on how to do this?

Thanks and best regards,

Hey there,

Steps are the following:

  1. Log in as an administrator
  2. Go to Plugins tab (top left menu)
  3. From the Script Runner section choose Script Listeners
  4. From the options there, choose Create sub task

After that you have to choose the event that your listener cathes and under witch conditions your listener will execute the desired action.

Check previous comments.

Kostas,

It worked for me. Thank you so much. Could you please tell me how do I assign each of the sub-task to a different assignee?

Regards,

Kostas,

The problem is - every time that I update anything in the ticket, sub-tasks are getting created. Is there a groovy script which I can run only when a date is chosen from the custom field?

Hey Vishali,

you should put a condition to the listener so it catches the event when condition is true.

e.g

cfValues['date_field'] == 'dd/mm/yyyy'

Add the condition when setting up the listener.

Cheers

Kostas,

Thank you for the valuable input. But when the license posting date is updated more than once, then sub-tasks are created more than once. What should I do in this scenario?

Thanks,

Hey Vishali,

in your existing condition add the following

&& issue.subTasks.size() <1

That way the listener will execute the action only when your issue doesn't have any subtask.

Test it first.

Hope that helps

Cheers

Based on the value selected in the position field, number of sub-tasks being created varies. After this, my listener works to create the extra sub-tasks. So it need not necessarily be <1. So, how should I handle this scenario?

Will a groovy script work in such scenario?

Thanks,

Hmm,

i think in your case a custom listener is the solution. If i'm not wrong, the current built in listener cannot control the number of created subtasks when issue is updated, one subtask is created every time that conditions are met.

Cheers

Hi,

Would the above work with some tweaking were I had a value of 3 within a number field on then on transition say "approved" to have 3 sub-tasks created?

Thanks

Once you start talking about doing this on a transition, then Create on Transition Plugin for JIRA applies and you can create multiple subtasks, etc... See How to create multiple issues for instance or one of the other similar pages.

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
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

74 views 0 5
Read article

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