Hi,
Perhaps someone can help me with following, I'm trying to create a transition post-function that adds user to a group (from a user picker custom field). However, when running below script...
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def groupManager = ComponentAccessor.getGroupManager()
def user = (ApplicationUser) ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Field Name").getValue(issue)
def group = groupManager.getGroup("Group1")
groupManager.addUserToGroup(user,group)
...I get this error
019-10-24 22:36:14,574 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-10-24 22:36:14,575 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ISSUE-66, actionId: 11, file: <inline script> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[user@user.com)]' with class 'java.util.ArrayList' to class 'com.atlassian.jira.user.ApplicationUser' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.user.ApplicationUser(com.atlassian.jira.user.DelegatingApplicationUser) at Script74.run(Script74.groovy:6
Hi QTR,
The problems is in:
ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Field Name").getValue(issue)
since this doesn't return an (ApplicationUser) but a List<ApplicationUser> you must then ensure that this value isn't return as null and iterate over each element calling the groupManager.addUserToGroup(user,group) for each eleement to add it to the desired group.
Regards
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.