Script Listener - Issue Assigned

Hi,

 

In my company, we have developed a Custom listener for the Issue Assigned Event that, after performing some validations to the "new" Assignee, it maintains, "clear" or modify the Assignee for that Issue. This works perfectly when we directly change the Assignee or by"Edit" button.
However, if the Assignee is changed on a Transition (we have the Assignee field on a screen that is shown during a status transition), the script runs (we have some emails that are sent via script during the validations), however, the Assignee does not change.


The "way" we are using to change assignee is:

currentIssue.setAssignee(otherIssue.getAssignee());
currentIssue.store();

 

And the Post Function that we have in a transition are, for example, as follows:

  1. Set issue status to the linked status of the destination workflow step.
  2. Add a comment to an issue if one is entered during a transition.
  3. Update change history for an issue and store the issue in the database.
  4. Re-index an issue to keep indexes in sync with the database.
  5. Fire a Generic Event event that can be processed by the listeners.

 

We have already tried to put the listener code between the "steps" (Post Functions) of the Transition, as well as in a Generic Event type Event (on Script Listeners), but the Assignee does not change (all code goes well, just does not change the Assignee)

 

Best Regards.

1 answer

1 accepted

1 vote
Alexey Matveev Community Champion Jan 04, 2018

Hello,

I do not understand how you tried to put the listener code between the steps. Listener fires when an event, which the listener listens, fires. I would put log.error message in your listener and see in the logs if the listener fires or not.  If the listener fires, but the assignee is not changed then something is wrong with your code, if the listener does not fire then you should make it fire by adding Generic event to the listener.

Hello Alexey,

Thank you very much for your reply.

We have placed the code in a Post Function, properly configured to change the Assignee in the Issue (the code is not exactly the same as on the Listener).
No error is returned. The code runs perfectly, all logs are successful, including the information that assignee changed, however, when the screen is closed, the assignee remains the one we choose manually on the screen and not what should be replaced by code (replacing the manually inserted).
We have already put it as Generic event and it happens the same.
By changing the Assignee directly or in the edit window, everything runs as expected and completely "error-free". When we change assignee on a status transition screen, it also does not return any errors, everything runs fine (on the "background") however, as soon as the screen closes, the assignee has not been replaced by what the code should have replaced.

 

Thank you again.

Alexey Matveev Community Champion Jan 04, 2018

Ok. Kindly change your script to this one . I think the problem is with issue.store();

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

currentIssue.setAssignee(otherIssue.getAssignee());
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

and you need to add an import

import com.atlassian.jira.event.type.EventDispatchOption

Try it with a post-function first. Put your post-function before reindexing

Hi Alexey,

This worked. Thank you very much.
If I put it this way only in the Listener it still does not work in the workflow transitions, but putting it in the Post Functions already works correctly. This way, I put the code (custom and with the "pieces" that you sent) in Post Function, so, what I intend is done here soon, so when it arrives at Listener everything is already as intended. I also let the Listener stay as it was and when we change Assignee directly, it works as it always did.


Thank you so much again.

Best regards.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,311 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot