Script to perform something on each user of a group (size of group is a variable) Edited

I am trying to procure a script that ultimately creates one subtask for each user in a custom-field-specified group. 

There are six possible groups, each of which is going to have a different number of users.

The group will be designated by a Single Group Picker custom field called "Needs approval from". For example, a customer could select "web-server-group", which contains three users. Or, they could select "network-device-group", which contains five users.

What I need

Code that will I need take the value of "Needs approval from", and for each user in the group, create one subtask, link it to parent issue, and (ideally) assign it to that user. The assignment is not crucial but would be very helpful.

Here is some VERY ROUGH pseudocode — I know that many of these steps require accessors, managers, etc. But this is the general outline of what I'm trying to accomplish.

group = ("Needs approval from").value
groupSize = group.size

int i 
for (i = 0; i < groupSize; i++) {
      currUser = group[i]
      newSubtask = createSubtask(currUser)
      newSubtask.assignToUser(currUser)
      newSubtask.linkToParentIssue
}

Any and all help turning the above pseudocode into functioning Groovy would be greatly appreciated.

I am very new to Groovy, but I do know how to use the ComponentAccessor and GroupManager. I'm having trouble understanding how to get the actual group in the form of a collection that allows me to iterate through it and perform actions on the elements (users) within it.

Notes: 

I have tried the Create Issue post function from the Create on Transition plugin from Bob Swift, which almost gets me there — it allows me to create multiple subtasks on one transition, but it doesn't accept a user group as the designator of how many subtasks to create. 

I am extremely averse to hardcoding groups, hardcoding custom fields with groups and their users, and using multiple workflows, because the idea is to replicate this process in other projects. If group membership changes, or if we implement this in several other projects, it will certainly cause more headaches than it prevents.

2 answers

This widget could not be displayed.

Hi Steve! For developer questions, it's better that you post them at community.developer.atlassian.com, that's where our developer community hangs out :)

Cheers,

Ana

This widget could not be displayed.

Hi Steve! For this kind of questions, I'd recommend you to go to community.developer.atlassian.com, so our developer community can help you out :)

Cheers,

Ana

Suggest an answer

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

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

195 views 1 3
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