Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Last issue comment, last issue comment author, last issue comment date/time Jira cloud

Ward Schwillens_ Schwillie
Contributor
November 7, 2022

Hi,

I'm looking for how to implement the last issue comment scripted field, with the example from the library. Additionally I would want to implement the same kind of scripted fields for the last issue comment author and last issue comment date/time. 

These fields are to appear in filter results. 

 

Anyone can share the screenshots for the setup on Jira cloud with some explanation and the script code? 

 

Thanks!

 

2 answers

1 accepted

1 vote
Answer accepted
Ward Schwillens_ Schwillie
Contributor
November 16, 2022

So with help from the scriptrunner support team I got it to work.

It starts with creating the appropriate custom fields: 2022-11-16 19 16 08 custom fields last comment.png

I created

  • "Last issue comment" as a single line text field
  • "Last issue comment author" as a User Picker (single user) field
  • "Last issue comment date/time" as a Date Time Picker field

Then in Scriptrunner I created this listener which listened on the Comment Created and Comment Updated events.

2022-11-16 19 14 26 Event Listener.png

The script itself then looked like this: 


//Last update by Ward Schwillens at 16/11/2022 18.27
final lastIssueCommentFieldName = 'Last issue comment'
final lastIssueCommentAuthorFieldName = 'Last issue comment author'
final lastIssueCommentDateTimeFieldName = 'Last issue comment date/time'

// Get custom fields properties
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
// Get last issue comment custom field id
def lastIssueCommentCfId = customFields.find { it.name == lastIssueCommentFieldName }?.id

// Updates the issue with the created comment body
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(lastIssueCommentCfId): comment.body
]
])
.asString()

// Get last issue comment author custom field id
def lastIssueCommentAuthorCfId = customFields.find { it.name == lastIssueCommentAuthorFieldName }?.id
// Updates the issue with the created comment author
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(lastIssueCommentAuthorCfId): comment.author
]
])
.asString()
// Get last issue comment date/time custom field id
def lastIssueCommentDateTimeCfId = customFields.find { it.name == lastIssueCommentDateTimeFieldName }?.id
// Updates the issue with the created comment date/time
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(lastIssueCommentDateTimeCfId): comment.created
]
])
.asString()


And after having created or updated an issue comment you can have the fields in a filter result. 

2022-11-16 18 29 44 filter result with last comment fields.png

0 votes
Bill Sheboy
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.
November 7, 2022

Hi @Ward Schwillens_ Schwillie 

What do you mean by "last issue comment scripted field"?

And to which library of examples are you referring?

If you are trying to use an automation rule to access this information, based upon the issue commented trigger, please look here for the smart values to use: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/#--issue.comments--

 

Kind regards,
Bill

Suggest an answer

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

Atlassian Community Events