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

Steve Van Der Weide May 3, 2017

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

0 votes
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 5, 2017

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

0 votes
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 5, 2017

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

Suggest an answer

Log in or Sign up to answer