The Adaptavist Group LogoDocumentation

Work with Comments

With HAPI, you can easily add comments to work items and retrieve comments from work items.

Add comments to a work item

You can add comments to a work item in Jira to provide updates, share progress, or communicate important information. Here's an example of how to add a comment:


workItem.addComment('Comment for administrators')
Note:JSM internal notes

Currently, workitem.addComment() adds only public comments in JSM using HAPI. Adding internal/private comments is not supported, however, a workaround is available using the REST API. For example:

def comment = """
				Hi, ${issue.fields.reporter.displayName} from ${issue.fields.customfield_12818.value} office,

				Thank you for creating this ticket in our service desk. You have requested a laptop replacement delivered to following destination:

				${issue.fields.customfield_12831}

				Please make sure the address is correct. We will respond to your request shortly.

				Kindly also note if the ticket remains inactive for a period of 10 days then will automatically be closed.
			"""

def addComment = post("/rest/servicedeskapi/request/${issue.key}/comment")
		.header('Content-Type', 'application/json')
		.body([
				body: comment,
				// Make comment visible in the customer portal
				public: true,
		])
		.asObject(Map)

assert addComment.status >= 200 && addComment.status <= 300

Retrieve all comments from a work item

Use the getComments function to fetch all comments associated with a work item.
def workItem = WorkItems.getByKey('JRA-1')
workItem.getComments()

// To retrieve specific properties of comments, such as the body, you can use:
workItem.getComments().collect { it.body }

Search documentation

Start typing to search the docs.