The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

I need a script runner code whenever a comment is added to an issue, comment size (no. Of comments)

Bhadram Neo
November 12, 2023

I need a script runner code that runs whenever a comment is added to an issue. The script should display the comment size (number of comments) in a custom field.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Murat Seven
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 Champions.
November 13, 2023

Hi @Bhadram Neo and thanks for your question.

 

You can use the following code in the ScriptRunner Listener. To find the number of comments, you can thoroughly examine the document.

 

customfield_10071 text field is a custom field.

 

// Get Issue Key 
def issueKey = issue.key

// Retrieve comments for the current issue
def issueResp = get("/rest/api/2/issue/${issueKey}/comment")
.header('Content-Type', 'application/json')
.asObject(Map).body as Map

// Log the total number of comments
logger.info("Comment Total Size: "+ issueResp.total)

// Update the issue with the total number of comments
put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_10071: issueResp.total.toString()
]
])
.asString()

Hope this helps. If the issue is resolved, you can vote and accepted for this comment.

 

Best,

Murat Seven

Bhadram Neo
November 13, 2023

Thank you for answering my question

DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events