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)

dv bhadram 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

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 Leaders.
November 13, 2023

Hi @dv bhadram 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

dv bhadram November 13, 2023

Thank you for answering my question

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events