Incomplete API Response when Internal Comment is restricted to Role

Jan Frischmuth
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 5, 2024

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}")
    }
The problem arises when a comment is set to internal and additionally restricted to a role.
Let's say in an example issue I have four comments
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
Then I get for the logging only comment 1, comment2 and comment4.
Comment3 is missing, even though it got the call that a comment was created. After Comment3, it'd log "Found 2 comments" and after Comment4 it'd log "Found 3 comments".
For whatever reason any role restriction that is not "Service Desk Team", the response doesn't seem to see these comments and I don't think there is a way to manually grant the Scriptrunner access to specific roles.
My question: is there a way to reliably get all comments in the API response? Could it be a bug or did I do a mistake?

1 answer

1 vote
Bobby Bailey
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.
December 5, 2024

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: 

Screenshot 2024-12-05 at 13.02.13.png

Kind regards, 

 

Bobby

Jan Frischmuth
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 10, 2024

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

Bobby Bailey
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.
December 13, 2024

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: 

 

image.png

 

Does this help?

Kind regards, 

Bobby

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events