With a Scriptrunner Listener script, I'm trying to access the comments in an issue.
def issueKey = issue.key
def allCommentsResponse = get("/rest/api/3/issue/${issueKey}/comment")
.header('Content-Type', 'application/json')
.asObject(Map)
if (allCommentsResponse.status == 200) {
def comments = allCommentsResponse.body.comments
logger.info("Found ${comments.size()} comments in issue ${issueKey}:")
comments.each { comment ->
def author = comment.author?.displayName ?: "Unknown"
def content = comment.body?.content?.collect { paragraph ->
paragraph?.content?.collect { item -> item?.text }.join(" ")
}.join("\n")
logger.info("Comment by ${author}: ${content}")
}
User 2 (05.12.2024 11:12) (internal, restricted to role Service Desk Team)comment4 text blabla
User 1 (05.12.2024 10:03) (internal, restricted to role Developer)comment3 text bar
User 2 (04.12.2024 15:17) (internal, no role restriciton)comment2 text xyz
User 1 (04.12.2024 13:51) (external for customer, no restriction)comment1 text foo
Hi Jan,
Just to check, are you setting this listener to run as the current user, or as the ScriptRunner Add-on user, in this field:
Kind regards,
Bobby
Hi Bobby,
running it as "Current user" does indeed solve the problem, thanks!
I'd like to keep run as "Scriptrunner AddOn-User" if possible, since it'd work disregarding of who's making the comment. Now, we'd have to give everyone the ability to comment (and browse) every effected project. That's why I'd prefer a solution where I don't have to run as "Current user". Do you know if that's a limitation or could it be a bug that'd be worth consolidating with Adaptavist?
Cheers, Jan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jan,
Sorry for the delay in my response.
From what I can see the only way I can find to add the user to the roles would be programmatically. You can get the ScriptRunner Add-on user account Id using the "Myself" REST API while running the script.
I have written a short example, you can find this here: https://bitbucket.org/Adaptavist/workspace/snippets/rqBGKz
The trick is to run the script in the console as the ScriptRunner Add-on user:
Does this help?
Kind regards,
Bobby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.