Anyone able to help with this script?

I have written this so far to try to create a subtask for each user in a customfield with the help of this other issue. 

workflow post-function: creating subtask for each user of group

@Jamie Echlin [Adaptavist] this was originally your solution I followed.

 

I keep getting an error that says:

/secure/WorkflowUIDispatcher.jspa [groovy.canned.utils.ConditionUtils] javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: ArrayList_delegateProxy.getUsers() is applicable for argument types: () values: []
Possible solutions: getClass(), getName(), every()

 

Any ideas what I am missing here?

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.crowd.embedded.api.Group;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.config.SubTaskManager
import org.ofbiz.core.entity.GenericValue

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
def issueFactory = componentManager.getIssueFactory()
def issueManager = componentManager.getIssueManager()
def indexManager = componentManager.getIndexManager()
def groupCf = customFieldManager.getCustomFieldObjectByName("Reviewers") // name of group CF

Group group = issue.getCustomFieldValue(groupCf) as Group
if (group) {
   group.getUsers().each {String user ->
        MutableIssue newIssue = issueFactory.getIssue()
        newIssue.summary = "Doc ERB Assessment for $user"
        newIssue.issueTypeId = '12600'
        newIssue.project = issue.project
        newIssue.assignee = UserUtils.getUser(user)
        newIssue.assigneeId = user
        Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
        def currentUser = componentManager.getJiraAuthenticationContext().getUser()
        GenericValue newIssueGv = issueManager.createIssue(currentUser, newIssueParams)
        indexManager.reIndex(newIssueGv);
        SubTaskManager subTaskManager = componentManager.getSubTaskManager()
        subTaskManager.createSubTaskIssueLink(issue, newIssue, componentManager.getJiraAuthenticationContext().getUser())
    }
 }

2 answers

0 vote

There's no method getUsers on com.atlassian.crowd.embedded.api.Group

Use for eg: com.atlassian.jira.user.util.UserUtil#getAllUsersInGroups

 

Hey Jamie,

I am still unable to get this script to generate subtasks for my customfield of users.

I put this as a condition on a script to create subtasks, I also tried it as the Additional issue actions. Neither seems to work.

 

Here is the script I have, any suggestions?

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.crowd.embedded.api.Group;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.config.SubTaskManager
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.user.UserUtils
import com.atlassian.jira.user.util.UserManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.security.util.GroupSelectorUtils 
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
def issueFactory = componentManager.getIssueFactory()
def issueManager = componentManager.getIssueManager()
def indexManager = componentManager.getIndexManager()
def groupCf = customFieldManager.getCustomFieldObjectByName("Reviewers") // name of group CF
def UserList = []
User currentUserObj = UserUtils.getUser(currentUser)
GroupSelectorUtils util = (GroupSelectorUtils) ComponentManager.getInstance().getContainer().getComponentInstanceOfType(GroupSelectorUtils.class) 
Group group = issue.getCustomFieldValue(groupCf) as Group
//issue.getCustomFieldValue(groupCf).each {Object group ->
if (group) {
//group.getUsers().each {String user ->
//Group groupObj = util.getGroups((String) group)
//groupObj.getAllUsersInGroup().each {String user ->
    def groupManager = ComponentAccessor.getGroupManager()
        groupManager.getUsersInGroup(group).each {String user ->
    if(!UserList.contains(user) && user != currentUser) {
        
        MutableIssue newIssue = issueFactory.getIssue()
        newIssue.summary = "Doc ERB Assessment for $user"
        newIssue.issueTypeId = '12600'
        newIssue.project = issue.project
        newIssue.assigneeId = user
        Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
        def currentUser = componentManager.getJiraAuthenticationContext().getUser()
        GenericValue newIssueGv = issueManager.createIssue(currentUser, newIssueParams)
        indexManager.reIndex(newIssueGv);
        SubTaskManager subTaskManager = componentManager.getSubTaskManager()
        subTaskManager.createSubTaskIssueLink(issue, newIssue, componentManager.getJiraAuthenticationContext().getUser())
        
        UserList.add(user)
         }
       }
    }
 }

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,310 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot