Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I tag a user in a comment, Jira CLOUD?

George Davies October 29, 2024 edited

I am trying to create my first code / script in Script runner for Jira Cloud but I am 3 months in and not succeeded yet. (Obviously, I have little to no coding experience)

I have a workflow in a project and I am trying to create a post function that emails a specific user once an issue has passed through this transition (which happens to be an escalation transition from 'waiting for support' to 'Escalated'). I have a working code that currently posts the name of the person and the relevant comment but it isn't 'tagging' the user. So it doesn't send them a notification. Is anyone able to tell me what I am missing, below is my code which is running in the post function:

final JOE_BLOGGS_ACCOUNT_NAME = "JOE BLOGGS"


def issueKey = issue.key

def commentText = "@${JOE_BLOGGS_ACCOUNT_NAME} this ticket has been Escalated."

def result = post("/rest/api/2/issue/${issueKey}/comment")
        .header('Content-Type', 'application/json')
        .body([
            body: commentText
        ])
        .asString()

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 30, 2024

Hi George,

Thank you for your question.

I can confirm the easiest way to see what value to set is to manually add a comment on an issue and then use the script console to make an API call to the Get Comments For Issue API to see what structure an at mention is stored as.

I have done this and see it stored like below, where you specify the user's account.

[~accountid:1234-3423432423-32423-234324324]

Using this, I have updated your comment text to use this structure and can confirm it added a comment with an at mention as require.

You will just need to update the accountId value to be the accountId of a user inside your instance.

I hope this helps.

Regards,

Kristian

George Davies October 30, 2024

Hi Kristian,

That has worked wonders, thank you so much. I have looked at that 'Get Comments For Issue API' link. Are you able to just tell me the script you put in the console to get the comment details to return? 

I have not used the console and when I pasted the example on the right and changed it to my issue I got red errors. 

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 30, 2024 edited

Hi George,

To get comments for an issue you can run a script similar to the script I have created here.

I hope this helps.

Regards,

Kristian

Like George Davies likes this
TAGS
AUG Leaders

Atlassian Community Events