Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

groovy script -->import com.opensymphony.user.Group error ?

NEWNEW September 17, 2018 edited

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())
}
}

 

1 answer

0 votes
Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 17, 2018

I think you should use import com.atlassian.crowd.embedded.api.Group;

group.getUsers() will not work. You can use the UserUtil.getAllUsersInGroupNames(...)

 

See com.atlassian.jira.user.util.UserUtil:

NEWNEW September 17, 2018

Hi Support,it doesn't work after I import com.atlassian.crowd.embedded.api.Group; ?

Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 17, 2018

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.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events