Casting error from DelegatingApplicationUser to api.User in post function script (Groovy)

I have a script that takes a member group and splits the current users into an email string that gets used by a custom email function. The error I am getting says 

2017-06-20 15:28:36,113 ERROR [workflow.ScriptWorkflowFunction]: Special Test Priority Value option: 5 - Stop working on everything else and get this done
2017-06-20 15:28:36,113 ERROR [workflow.ScriptWorkflowFunction]: The reporter is: Hank Hepler
2017-06-20 15:28:36,113 ERROR [workflow.ScriptWorkflowFunction]: Testing out DSTR 
2017-06-20 15:28:36,160 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-06-20 15:28:36,160 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'a092rzz(a092rzz)' with class 'com.atlassian.jira.user.DelegatingApplicationUser' to class 'com.atlassian.crowd.embedded.api.User'
	at Script104.getGroupEmails(Script104.groovy:83)
	at Script104.run(Script104.groovy:55)

I fixed the null issue error, but am kind of lost on the casting of the object. How can I get the users in the correct object (User)? Below is the function... we just upgraded to 7 so I have this in multiple places.

def getGroupEmails(String groupName)
{
	def gusers = new StringBuilder();
	def userManager = ComponentAccessor.getUserManager();
	def groupManager = ComponentAccessor.getGroupManager();
	def group = userManager.getGroup(groupName);
	List<User> usersInGroup = (List)groupManager.getDirectUsersInGroup(group)

	for (User user : usersInGroup){
		if (gusers.length() > 0) gusers.append( ", " );
		gusers.append( user.getEmailAddress() );    
	}
	return gusers.toString();
}

Any help will be greatly appreciated!

 

Thanks,

Hank
3M Systems Engineer

1 answer

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

72 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you