Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

arama mihai
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.
April 21, 2021

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

2 votes
Answer accepted
PD Sheehan
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.
April 22, 2021

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