Best way to create multiple sub-tasks, one for each value in a checkbox list

Brian Leysath March 4, 2017

Looking for insight into the best way to solve this issue:

  • Have a checkboxes custom field with about 10 options
  • Whenever one of the checkboxes is selected, a sub-task should be created.
  • The assignee for each subtask could be different
  • When boxes are checked could vary, so I believe I need to use a listener rather than a post-function.  Would Live Fields be an option as well?
  • Would prefer the functionality be in a single script rather than multiple if possible.
  • Have both JJupin and Scriptrunner plugins available
  • I'm not a developer - I typically search until I find close enough examples that I can copy

I started setting this up using the ScriptRunner Create Subtask function, but looks like I'll need to create a listener function for each option, which is not ideal.  However this does appear to handle all my needs, other than I'm unsure how to code the condition to ensure it doesn't create new subtasks nor modify existing ones for values that were previously checked.  Currently the Scriptrunner condition is using the following:

'My value' in cfValues['My Multi List']*.value

Any assistance would be greatly appreciated!

 

1 answer

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 5, 2017

You will need a listener but quite a complex one because there's quite a lot of things you need to think through.  It's definitely better to use a single one though, rather than one per option.

On events "issue updated" or "issue transition"

  • Check the content of the event for changes to your custom field (if none, then do nothing)
  • Look at the changes to the field value, and
    • For any selection that was not set and now is,
      • Check for a subtask existing already,
      • if none found, create
  • For any selection that was removed/unchecked
    • Not sure - possibly nothing, possibly close existing sub-tasks, possibly delete (although that would be something I'd strongly recommend not doing)
Brian Leysath March 6, 2017

Thank you for the response Nic.  I'm not concerned with boxes that may later be unchecked, so the 3rd bullet point you list can be ignored.  For the other 2, what would be the best way to compare the original field values to the new?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 6, 2017

I'd run JQL to read through the existing sub-tasks for the issue and compare them with what I might be creating - any close match found, don't create it. 

Last time I did this, there was a simple case - we were creating sub-tasks by component, so a simple "parent = current issue and component = <component we're thinking of creating for>" test applied.

Suggest an answer

Log in or Sign up to answer