Hi Support,
When I import com.opensymphony.user.Group,it occurred the following error
Please help us solve this error .
Thank you in advance!
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script3.groovy: 10: unable to resolve class com.opensymphony.user.Group @ line 10, column 1. import com.opensymphony.user.Group; ^ 1 error
We want to create sub-task according to group list members and assign those members to assignee.
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.project.Project;
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;
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
def issueFactory = componentManager.getIssueFactory()
def issueManager = componentManager.getIssueManager()
def indexManager = componentManager.getIndexManager()
//Issue issue = issue
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("AAA-254");
def groupCf = customFieldManager.getCustomFieldObjectByName("alarm_group")
Group group = issue.getCustomFieldValue(groupCf) as Group
if (group) {
group.getUsers().each {String user ->
MutableIssue newIssue = issueFactory.getIssue()
newIssue.summary = "Sub-task for $user"
newIssue.issueTypeId = '5'
newIssue.project = issue.project
newIssue.affectedVersions = issue.affectedVersions
newIssue.fixVersions = issue.fixVersions
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())
}
}
I think you should use import com.atlassian.crowd.embedded.api.Group;
group.getUsers() will not work. You can use the UserUtil.getAllUsersInGroupNames(...)
Hi @NEWNEW
Please be aware this is not Atlassian Support. And Atlassian Support will not help you with your custom scripts. This is a public community.
Changing that import was a start. You need to adapt other parts as well.
Here is a code snippet that works for me.
It gets each group in your custom field (assuming it is a multi group picker but it could be a single picker as well).
Then it gets all users in those groups and loops over them.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.api.Group;
import com.atlassian.jira.user.util.UserUtil;
import com.atlassian.jira.issue.CustomFieldManager;
UserUtil userUtil = ComponentAccessor.getUserUtil();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("AAA-254");
def groupCf = customFieldManager.getCustomFieldObjectByName("alarm_group")
List <Group> groups = issue.getCustomFieldValue(groupCf) as List <Group>
def userList = userUtil.getAllUsersInGroupNames(groups.name)
userList.each{ user ->
// do what you need to do for each user
}
I hope this helps you a bit further.
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.