Skip to content

Instantly share code, notes, and snippets.

/CreateSubTasks
Created Feb 14, 2012

Embed
What would you like to do?
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.opensymphony.user.Group
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.config.SubTaskManager
import org.ofbiz.core.entity.GenericValue
import com.opensymphony.user.User
import com.atlassian.core.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("Kompetenzcluster") // name of group CF
def UserList = []
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller()
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 groupObj = util.getGroups((String) group)
groupObj.getUsers().each {String user ->
if(!UserList.contains(user) && user != currentUser) {
MutableIssue newIssue = issueFactory.getIssue()
newIssue.summary = "$user: " + issue.summary
newIssue.issueTypeId = '71'
newIssue.project = issue.project
newIssue.reporter = UserUtils.getUser(user)
newIssue.assignee = UserUtils.getUser(user)
newIssue.assigneeId = user
newIssue.priority = issue.priority
//newIssue.affectedVersions = issue.affectedVersions
//newIssue.fixVersions = issue.fixVersions
Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
//User currentUser = componentManager.getJiraAuthenticationContext().getUser()
GenericValue newIssueGv = issueManager.createIssue(currentUserObj, newIssueParams)
indexManager.reIndex(newIssueGv);
SubTaskManager subTaskManager = componentManager.getSubTaskManager()
subTaskManager.createSubTaskIssueLink(issue, newIssue, componentManager.getJiraAuthenticationContext().getUser())
indexManager.reIndex(newIssueGv);
indexManager.reIndex(issue);
UserList.add(user)
}
}
}
}
@anushagvk

This comment has been minimized.

Copy link

anushagvk commented Jul 20, 2016

When I added the code for creating auto subtask for a list of users in the group.
please help me in resolving this error ""No such property: issue for class:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.