scriptrunner-public-2.0.9 /src/test/resources/examples/AssignSubTass.groovy

Language Groovy Lines 61
MD5 Hash 3ae09ce2b147d9481468a822df7149d3
Repository https://bitbucket.org/aschuma/scriptrunner-public-2.0.9 View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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)

            }
        }
    }
}
Back to Top