Skip to content

Instantly share code, notes, and snippets.

Created February 14, 2012 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1825347 to your computer and use it in GitHub Desktop.
Save anonymous/1825347 to your computer and use it in GitHub Desktop.
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
Copy link

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