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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 45m ago in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

38 views 3 3
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