Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get the recipients for an event in the notification scheme in groovy? Edited

Hello,

 

I have the following code:

 

def firstProjectKey = 'ABC'
def getFirstProject = projectManager.getProjectByCurrentKeyIgnoreCase(firstProjectKey)
NotificationSchemeManager nsm = ComponentAccessor.getNotificationSchemeManager()
def firstProjectNotificationScheme = nsm.getSchemeFor(getFirstProject)
Collection<EventType> allEventTypes = etm.getEventTypes()
for (event in allEventTypes) {
def recipientsInProject1 = nsm.getRecipients(event,firstProjectNotificationScheme)
}

 

My objective is to get for each event (issue created, issue edited, etc.) in the notification scheme of a specific project , the recipients (perhaps a group, reporter, current assignee, a project role, etc.).

I see in here: https://docs.atlassian.com/software/jira/docs/api/7.1.1/com/atlassian/jira/notification/NotificationSchemeManager.html that the getRecipients() method is available, and is expecting :  getRecipients(IssueEvent event,SchemeEntity notification)

When running my script in the console I get:

Script console script failed: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.notification.DefaultNotificationSchemeManager.getRecipients() is applicable for argument types: (com.atlassian.jira.event.type.EventType, com.atlassian.jira.scheme.Scheme) values: [EventType{id=1, name='Issue Created', description='This is the 'issue created' event.', type='jira.system.event.type', templateId=null}, ...] Possible solutions: getRecipients(com.atlassian.jira.event.issue.IssueEvent), getRecipients(com.atlassian.jira.event.issue.IssueEvent, com.atlassian.jira.scheme.SchemeEntity) at Script3131.run(Script3131.groovy:388)

or, if I try with the id:

 Script console script failed: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.notification.DefaultNotificationSchemeManager.getRecipients() is applicable for argument types: (Long, Long) values: [1, 10700] Possible solutions: getRecipients(com.atlassian.jira.event.issue.IssueEvent), getRecipients(com.atlassian.jira.event.issue.IssueEvent, com.atlassian.jira.scheme.SchemeEntity) at Script3135.run(Script3135.groovy:388)

Please let me know what is the expected type of data here.

Thank you!

1 answer

1 accepted

1 vote
Answer accepted

A few issues with your approach ...

SchemeEntity (expected by getRecipient) != Scheme  (result of getSchemeFor)
IssueEvent (expected by getRecipient) != EventType (result of getEventTypes)

The getRecipient is really expected to work in the context of a specific issue since some of the recipients could be based on field values in the issue and it would return the actual recipient object (with user, user's email and user's email format preference).

Maybe this will get you closer to what you want:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.event.type.EventTypeManager
def prm = ComponentAccessor.getComponent(ProjectRoleManager)
def etm = ComponentAccessor.getComponent(EventTypeManager)
def nsm = ComponentAccessor.notificationSchemeManager

def proj = ComponentAccessor.projectManager.getProjectObjByKey('JSP')
def ns = nsm.getSchemeFor(proj)

ns.entities.each{entity->
def et = etm.getEventType(entity.entityTypeId)
def param = entity.parameter ?: ''
if(entity.type == 'Project_Role'){
param = prm.getProjectRole(param.toLong()).name
}
log.info "$et.name - $entity.type${param ? "[$param]": ''}"
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

247 views 2 1
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you