Forums

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

user mentions don't work in comment added by script

Bartek Zukowski
Contributor
July 5, 2019

Hello,

I have a script listener that should add a comment and mention a user in it but for some reason, even though it adds a comment properly, it doesn't generate a mail for the mentioned user. It's strange, because we have couple of similar listeners/postfunctions and they work in every case except this one. Here is the script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventType

def cm = ComponentAccessor.commentManager

def um = ComponentAccessor.userManager
def cprbot = um.getUserByName("cpr_bot")

def components = ["fashion", "teeth", "COMPRESSTOCKING"]*.toLowerCase()

def event = event as IssueEvent
def comBody = "[~drnovseku] prośba o update. Test powiadomienia: [~bugajk]"
def addComment = {
cm.create(event.issue, cprbot, comBody, true)
}

log.warn "DOSTEPY ${event.eventTypeId} ${EventType.ISSUE_UPDATED_ID}"

if (event.eventTypeId == EventType.ISSUE_CREATED_ID) {
if (event.issue.getComponents()*.name.intersect(components).size() > 0) {
cm.create(event.issue, cprbot, comBody, true) //addComment()
}
} else if (event.eventTypeId == EventType.ISSUE_UPDATED_ID) {
def changeLog = event.getChangeLog()
def changeItems = changeLog.getRelated("ChildChangeItem")
def fieldChanged = changeItems.findAll {it.getString('field') == "Component"}
if (fieldChanged.size() > 0) {
def old = fieldChanged*.getString('oldstring')
def nju = fieldChanged*.getString('newstring')
if (components.any {!old?.contains(it) && nju?.contains(it)}) {
cm.create(event.issue, cprbot, comBody, true) //addComment()
}
}
}

 Any idea why the users don't receive any notifications from this comment but they receive notifications from mentions anywhere else? Their emails in Jira are correct and they have access for the ticket with comment.

Also the comment itself looks good enough for me:

CPR 17455  test powiadomienia   JIRA.png

1 answer

0 votes
Ben Poulson
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.
July 8, 2019
def comBody = "[~drnovseku] prośba o update. Test powiadomienia: [~bugajk]"

I believe the [~] needs to contain the users email address, not their name. 

Bartek Zukowski
Contributor
July 10, 2019

Hi Ben,

When you're mentioning someone, you need to use their username in [~]. Using e-mail address only creates a comment with an e-mail address but without mentioning anyone:

CPR 17455  test powiadomienia   JIRA v2.png

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events