How to find email address from project role member in scriptrunner

I have a scriptrunner custom email post function.  I'd like to setcc based on the email address from Project Role.    I searched the old Q&A area and it seems there is no direct ay to obtain the email addresses directly.  One solution seems to scan through all users and check if match project role.   But I couldn't get that to work either.   Is there any direct function that I can use to obatin the list of email address based on the role?

1 answer

You will be able to do this with the following code in the "Condition and Configuration" section of the send a custom email script.

def projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)

def roleName = "jira-administrators"

def projectRole = projectRoleService.getProjectRoleByName(roleName, new SimpleErrorCollection("role error", [] as Set))

def actors = projectRoleService.getProjectRoleActors(projectRole, issue.projectObject, new SimpleErrorCollection("actors error", [] as Set))

def ccAddresses = actors?.getApplicationUsers()*.emailAddress.join(",")

if (ccAddresses) { mail.setCc(ccAddresses)
} true // so the script fires as the last statement is evaluated as a condition 


You should change roleName to whatever project role you want to use is.

Let us know how that goes.

Thanks for the sample codes.  

I have been trying to resolve some static errors without much success.  Probably because of my lack of knowledge about the java libraries & programming.

Initially, I got an error about SimpleErrorCollection not found.  So I added 

import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.jira.bc.projectroles.DefaultProjectRoleService


I now have static error complaining not able to find matching method  com.atlassian.jira.component.ComponentAccessor#getComponent

I had already added 
import com.atlassian.jira.component.ComponentAccessor


Woukd appreciate additional pointers to help me resolve these static errors

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 11 hours ago 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...

35 views 0 3
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