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())
}
}
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)
}
}
}
}
There's no method getUsers on com.atlassian.crowd.embedded.api.Group
Use for eg: com.atlassian.jira.user.util.UserUtil#getAllUsersInGroups
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.