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 @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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.