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

Hank Hepler June 20, 2017

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 erro 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

 

7 answers

1 accepted

1 vote
Answer accepted
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2017

Hi Hank,

Apologies for the delay in responding. In JIRA 7 the User is now an ApplicationUser. So the method where you get the users in a group actually returns ApplicationUser's now.

You can find more information in this section of our documentation found here. There's also more information to help you change you update your scripts for 7 there so it's well worth a read.

I've taken this opportunity to tidy up your code a bit and simplify your logic, hope you don't mind:

import com.atlassian.jira.component.ComponentAccessor

def getGroupEmails(String groupName) {
    def userManager = ComponentAccessor.getUserManager()
    def groupManager = ComponentAccessor.getGroupManager()
    def group = userManager.getGroup(groupName)
    def usersInGroup = groupManager.getDirectUsersInGroup(group)

    usersInGroup.each { user ->
        if (gusers.length() > 0) {
            gusers.append(",")
        }

        gusers.append(user.getEmailAddress())
    }
    
    def groupUsers = usersInGroup*.emailAddress.join(",")

    groupUsers
}

Let us know how you get on with that.

Thanks,
Adam

Hank Hepler July 13, 2017

Thanks Adam... works well now!!

 

Best regards,

Hank

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2017

Hi Hank,

Apologies for the delay in responding. In JIRA 7 the User is now an ApplicationUser. So the method where you get the users in a group actually returns ApplicationUser's now.

You can find more information in this section of our documentation found here. There's also more information to help you change you update your scripts for 7 there so it's well worth a read.

I've taken this opportunity to tidy up your code a bit and simplify your logic, hope you don't mind:

import com.atlassian.jira.component.ComponentAccessor

def getGroupEmails(String groupName) {
    def userManager = ComponentAccessor.getUserManager()
    def groupManager = ComponentAccessor.getGroupManager()
    def group = userManager.getGroup(groupName)
    def usersInGroup = groupManager.getDirectUsersInGroup(group)

    usersInGroup.each { user ->
        if (gusers.length() > 0) {
            gusers.append(",")
        }

        gusers.append(user.getEmailAddress())
    }
    
    def groupUsers = usersInGroup*.emailAddress.join(",")

    groupUsers
}

 

Let us know how you get on with that.

Thanks,
Adam

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2017

Apologies for the delay in responding. In JIRA 7 the User is now an ApplicationUser. So the method where you get the users in a group actually returns ApplicationUser's now.

You can find more information in this section of our documentation found here. There's also more information to help you change you update your scripts for 7 there so it's well worth a read.

I've taken this opportunity to tidy up your code a bit and simplify your logic, hope you don't mind:

import com.atlassian.jira.component.ComponentAccessor

def getGroupEmails(String groupName) {
    def userManager = ComponentAccessor.getUserManager()
    def groupManager = ComponentAccessor.getGroupManager()
    def group = userManager.getGroup(groupName)
    def usersInGroup = groupManager.getDirectUsersInGroup(group)

    usersInGroup.each { user ->
        if (gusers.length() > 0) {
            gusers.append(",")
        }

        gusers.append(user.getEmailAddress())
    }
    
    def groupUsers = usersInGroup*.emailAddress.join(",")

    groupUsers
}

Let us know how you get on with that.

Thanks,
Adam

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2017

Hi Hank,

Apologies for the delay in responding. In JIRA 7 the User is now an ApplicationUser. So the method where you get the users in a group actually returns ApplicationUser's now.

You can find more information in this section of our documentation found here. There's also more information to help you change you update your scripts for 7 there so it's well worth a read.

I've taken this opportunity to tidy up your code a bit and simplify your logic, hope you don't mind:

import com.atlassian.jira.component.ComponentAccessor

def getGroupEmails(String groupName) {
    def userManager = ComponentAccessor.getUserManager()
    def groupManager = ComponentAccessor.getGroupManager()
    def group = userManager.getGroup(groupName)
    def usersInGroup = groupManager.getDirectUsersInGroup(group)

    usersInGroup.each { user ->
        if (gusers.length() > 0) {
            gusers.append(",")
        }

        gusers.append(user.getEmailAddress())
    }
    
    def groupUsers = usersInGroup*.emailAddress.join(",")

    groupUsers
}

Let us know how you get on with that.

Thanks,
Adam

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2017

Hi Hank,

Apologies for the delay in responding. In JIRA 7 the User is now an ApplicationUser. So the method where you get the users actually returns ApplicationUser's now.

You can find more information in this section of our documentation found here. There's also more information to help you change you update your scripts for 7 there so it's well worth a read.

I've taken this opportunity to tidy up your code a bit and simplify your logic, hope you don't mind:

import com.atlassian.jira.component.ComponentAccessor

def getGroupEmails(String groupName) {
    def userManager = ComponentAccessor.getUserManager()
    def groupManager = ComponentAccessor.getGroupManager()
    def group = userManager.getGroup(groupName)
    def usersInGroup = groupManager.getDirectUsersInGroup(group)

    usersInGroup.each { user ->
        if (gusers.length() > 0) {
            gusers.append(",")
        }

        gusers.append(user.getEmailAddress())
    }
    
    def groupUsers = usersInGroup*.emailAddress.join(",")

    groupUsers
}

Let us know how you get on with that.

Thanks,
Adam

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2017

Hi Hank,

Apologies for the delay in responding. In JIRA 7 the User is now an ApplicationUser. So the method where you get the users actually returns ApplicationUser's now.

You can find more information in this section of our documentation found here. There's also more information to help you change you update your scripts for 7 there so it's well worth a read.

I've taken this opportunity to tidy up your code a bit and simplify your logic, hope you don't mind:

import com.atlassian.jira.component.ComponentAccessor

def getGroupEmails(String groupName) {
    def userManager = ComponentAccessor.getUserManager()
    def groupManager = ComponentAccessor.getGroupManager()
    def group = userManager.getGroup(groupName)
    def usersInGroup = groupManager.getDirectUsersInGroup(group)

    usersInGroup.each { user ->
        if (gusers.length() > 0) {
            gusers.append(",")
        }

        gusers.append(user.getEmailAddress())
    }
    
    def groupUsers = usersInGroup*.emailAddress.join(",")

    groupUsers
}

Let us know hoiw you get on with that.

Thanks,
Adam

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2017

Hi Hank,

Apologies for the delay in responding. In JIRA 7 the User is now an ApplicationUser. So the method where you get the users actually returns ApplicationUser's now.

You can find more information in this section of our documentation found here. There's also more information to help you change you update your scripts for 7 there so it's well worth a read.

I've taken this opportunity to tidy up your code a bit and simplify your logic, hope you don't mind:

import com.atlassian.jira.component.ComponentAccessor

def getGroupEmails(String groupName) {
    def userManager = ComponentAccessor.getUserManager()
    def groupManager = ComponentAccessor.getGroupManager()
    def group = userManager.getGroup(groupName)
    def usersInGroup = groupManager.getDirectUsersInGroup(group)

    usersInGroup.each { user ->
        if (gusers.length() > 0) {
            gusers.append(",")
        }

        gusers.append(user.getEmailAddress())
    }
    
    def groupUsers = usersInGroup*.emailAddress.join(",")

    groupUsers
}

Let us know hoiw you get on with that.

Thanks,
Adam

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events