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

This widget could not be displayed.

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

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

 

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

536 views 23 15
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