Hi ,
I tried creating a last comment script which will return the last comment added in the issue.
I have added a scripted field to get the details , but in that when i tag people in the comment , We are getting atlassian id instead of name.
Code :
You can take the ID Account that is showing you and pass it to the Displayname to add it to the comment
import groovy.json.JsonSlurper
import org.slf4j.LoggerFactory
def logger = LoggerFactory.getLogger(this.class)
def issueKey = "XX-123"
def accountId = "634..............."
// Get user information
def userResponse = get("/rest/api/3/user?accountId=${accountId}")
.header('Content-Type', 'application/json')
.asObject(Map)
if (userResponse.status == 200) {
def user = userResponse.body
def displayName = user.displayName
// ADF format for mentioning a user
def adfComment = [
type: "doc",
version: 1,
content: [
[
type: "paragraph",
content: [
[
type: "text",
text: "This ticket was handled by "
],
[
type: "mention",
attrs: [
id: accountId,
text: "@${displayName}"
]
],
[
type: "text",
text: "."
]
]
]
]
]
def commentResponse = post("/rest/api/3/issue/${issueKey}/comment")
.header("Content-Type", "application/json")
.body([body: adfComment])
.asString()
if (commentResponse.status == 201) {
logger.info("Comment added successfully to issue ${issueKey}.")
} else {
logger.error("Error adding comment to issue ${issueKey}. Status: ${commentResponse.status}, Message: ${commentResponse.body}")
}
} else {
logger.error("Error retrieving user details for accountId ${accountId}. Status: ${userResponse.status}, Message: ${userResponse.body}")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.