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.
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 issuedef issueResp = get("/rest/api/2/issue/${issueKey}/comment") .header('Content-Type', 'application/json') .asObject(Map).body as Map// Log the total number of commentslogger.info("Comment Total Size: "+ issueResp.total)// Update the issue with the total number of commentsput("/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
Thank you for answering my question
It looks like you're new here. Sign in or register to get started.