Custom Issue Commented Event

Arianna Fabbri February 19, 2015

Hi,

I'm trying to setup a custom event with template Issue Commented that is thrown (through a Script Listener) when a Issue Commented event is thrown, except for comments added by a specific user.

 

I've created the new event like:

Task Commented              => Template = Issue Commented

 

...and I've added the related Script Listener:

Project: XXX

Event: Issue Commented

Condition:

import com.atlassian.jira.component.ComponentAccessor
if (comments) {
    //return comments*.authorKey[-1] == "Anonymous"
    return ComponentManager.getCommentManager().getComments(issue).last().author == "Anonymous"
} else {
    return false
}

Event: Task Commented

 

I've associated to the new event the requested notifications and then had a test.

The result is:

Task Commented notification arrives but it has no comment in it's body:

TaskCommented.png

 

If I do the same test enabling notifications for event Issue Commented (the original one) I get the notification with the comment within it's body.

 

Why this?

How can I reach the requested result?

Thank you in advance

Regards

4 answers

1 accepted

2 votes
Answer accepted
JamieA
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.
February 20, 2015

I actually think there is an issue here. There is a built-in script called something like "Fire a comment when..." that you can use to raise an event but only under specific circumstances.

If you choose the Issue Comment event, then the event is raised, but the vm mail templates try to get the comment from the event, but the event was raised without attaching any comment to it.

I think this is probably a bug.

Recently I posted an answer on how to use a custom script to raise an Issue Commented event that attaches the most recent comment: https://answers.atlassian.com/questions/11976112. Note that my original answer is not correct, the correct answer is in a gist in the comment.

1 vote
Alejo Villarrubia [Adaptavist]
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.
February 20, 2015

Hi @Arianna Fabbri,

Is there any reason why you cannot use directly the System Issue Event? According to the condition from your code, you could simply configure that event to trigger that event for the "Single User" called Anonymous.

Custom events are mainly used to generate notifications for custom workflow transitions.

0 votes
Arianna Fabbri February 20, 2015

Hi @Jamie Echlin [Adaptavist]

thank you for your answer but I think that my case is a little bit different: I have to catch (in addition to generic events for which your link is very useful) all the standard Issue Commented event and distinguish from who it has been added and then decide if I have to notify it to the users or not...

How can I do that?

Thank you

JamieA
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.
February 20, 2015

It's really the same question... you already have your condition, then you use the script to raise a new event, called eg Issue Anonymously Commented, which you catch in your notification scheme.

Arianna Fabbri February 20, 2015

Passing, wile raising it, the comment just added. Perfect, now I have understood. Thank you very much

Alejo Villarrubia [Adaptavist]
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.
February 20, 2015

I've been taking a look at @Jamie Echlin [Adaptavist] answer and that is definitely the correct one.

0 votes
Arianna Fabbri February 20, 2015

Hi @Alejo Villarrubia [Adaptavist]

I need to distinguish between internal comments (added by users directly from Jira) and comments added via email from Anonymous user.

I created a custom Task Internal comment Event and I would like to trigger the custom event only if the comment is added not by Anonymous (in the above condition I've made an error, it must be != "Anonymous").

In this way I can associate to the custom event, in the notification scheme, the users that have to receive notification for all the internal comment (not added from Anonymous)

Thank you

Suggest an answer

Log in or Sign up to answer