Need assistance to write a custom listener?

Hi all/Jamie,

I need assistance with a custom listener, based on (https://answers.atlassian.com/questions/292619/move-issues-assignee-automatically-project-lead-only-please-assist?page=1#292652)

1. I have create a permission scheme that allows users in role (Operational Support) to be allowed to move issues between projects, but not assign permission. These tasks need to be assigned to the project lead automatically.

2. I need a listener that will recognise a user in role (Operational Support) when moving a task between projects. During the moved the assignee needs to become the project lead.

Once the project lead has recieved the issue, this person has the permission to assign it the the correct person based on the priority on the issue.

Can anyone assist me?

1 answer

Hi Warren,

I would suggest you write a custom listener that listens for Issue Moved events. From the IssueEvent class you can get all information about the project and the user who initiated the event. Make use of the ProjectRoleManager (https://docs.atlassian.com/jira/6.2.1/com/atlassian/jira/security/roles/ProjectRoleManager.html) to check if the user who initiated the event has the Operational Support role. If so you can get the project lead user object from the current project and set this as a assignee for the project.

Feel free to ask more questions :) Hope this gets you started?!

Hi Benji,

I have never written a custom listener before, I will require assistance from start to finish? Can you help?

Where should I start and what knowledge is requred?

Thanks

Hi Warren,

In this case I would suggest you start here:

https://developer.atlassian.com/display/JIRADEV/Writing+JIRA+Event+Listeners+with+the+atlassian-event+Library

This tutorial learns you how to write a custom plugin that registers a listener to receive issue events. The programming language used here is Java, but the basics for other languages (f.e Groovy) is the same.

Once the previous tutorial was completed you will have access to an IssueEvent object:

https://docs.atlassian.com/jira/6.2.3/com/atlassian/jira/event/issue/IssueEvent.html

From this class you can retreive info about the event:

- User that started the event

- Issue project

- Issue itself

-...

The next step is to check that the user who initiated the event has the group Operational support and this is done via the GroupManager:

https://docs.atlassian.com/jira/6.2.1/com/atlassian/jira/security/groups/GroupManager.html

The method getUsersInGroup returns all users that are part of a certain group. To check wether the user from the IssueEvent is in this list of users. Then you know that he also has the group Operational Support.

Your listener has to keep some state, because an issue move event from one project to another consists of 2 event:

1) Project 1 will throw a move event

2) Project 2 will throw a create event

https://confluence.atlassian.com/display/JIRA/Moving+an+Issue

You have to check that when you retrieve a create event in project 2 that a move event was also fired in project 1 for the same issue. Otherwise the create event was not caused by an issue move.

The last step is to update the issue assignee and this is done with the IssueService:

https://developer.atlassian.com/display/JIRADEV/Performing+Issue+Operations#PerformingIssueOperations-EditinganexistingIssue

The IssueInputParameter you need to set is setAssigneeId.

When the create event for project 2 was fired you can retrieve the project from the IssueEvent class and next retrieve the project lead user object from the Project class:

https://docs.atlassian.com/jira/6.2.1/com/atlassian/jira/project/Project.html

In order to use your plugin you have to upload it to your JIRA instance:

https://confluence.atlassian.com/display/UPM/Installing+add-ons

Hope this gets you on track?!

Thanks, I'll make a start and then comment back if i get stuck.

Ok, I'll check for updates :)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Agile

What is Scrum? A good, bad, and ugly answer.

In a world of dark-scrum, faux-scrum, and scrum-butt, the question still remains: What is scrum and how do you do it “right?” That’s the question we set out to answer. I'm Max, I've been teaching c...

59 views 0 1
Join discussion

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