Work with Comments

With HAPI, you can easily add comments to issues and restrict who can see the comments. 

To work with comments in Jira Service Management see this page.

Adding a comment to an existing issue

You can add a comment to an existing issue. For example:

            Issues.getByKey('SR-1').addComment('This is a comment')

Adding a comment while updating an issue

You can add a comment while updating an issue. For example:

            def issue = Issues.getByKey('SR-1')
        
            issue.update {
                setDescription('I am updating the description')
                setComment('This is a comment')
            }

Image showing how to add a comment while updating an issue with HAPI

Adding a comment while transitioning an issue

You can add a comment while transitioning an issue. 

In this example we're resolving an issue, setting the resolution, and adding a comment.

            def issue = Issues.getByKey('ABC-1')
 
            issue.transition('Resolve Issue') {
                setResolution('Done')
                setComment('resolving this issue')            
            }        

You can see more about transitioning issues on this page.

Setting restrictions 

Setting group restrictions

You can restrict which groups can see a comment.

In this example we're adding a comment to an existing issue and restricting the comment to the "jira-administrators" group.

            def issue = Issues.getByKey('SR-1')
  
            issue.update {
                setComment('This is a comment') {
                    setGroupRestriction('jira-administrators')
                }
            }

Setting project role restrictions

You can restrict which project roles can see a comment. 

In this example we're adding a comment to an existing issue and restricting the comment to the "Administrators" role.

            def issue = Issues.getByKey('SR-1')

            issue.update {
                setComment('This is a comment') {
                    setProjectRoleRestriction('Administrators')
                }
            }



Related content

On this page