Hi fellow
I have a script that adds the last comment to a custom field called "last comment"
I also add the comment author to the last comment author custom field, and the comment created date/time into a last comment created date/time field.
But in the overview on a dashboard, using a filter result, this tends to get quite wide.
Therefor I want to add the comment author and comment created date time at the bottom of the last comment custom field, preferably on a new line and with a title: "Author : " and "Comment Created Date/time : " before the actual data.
How can I do that?
//Last update by Ward Schwillens at 11/03/2024 11.32
final ProjectReportCommentFieldName = 'Project Report Comment'
final lastProjectReportCommentAuthorFieldName = 'Last Project Report comment author'
final lastProjectReportCommentDateTimeFieldName = 'Last Project Report comment date/time'
def titleAuthor = 'Author :'
def titleDateTime = '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 ProjectReport comment custom field id
def ProjectReportCommentCfId = customFields.find { it.name == ProjectReportCommentFieldName }?.id
// Get last issue comment author custom field id
def lastProjectReportCommentAuthorCfId = customFields.find { it.name == lastProjectReportCommentAuthorFieldName }?.id
// Get last issue comment date/time custom field id
def lastProjectReportCommentDateTimeCfId = customFields.find { it.name == lastProjectReportCommentDateTimeFieldName }?.id
// Updates the issue with the created comment body
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(ProjectReportCommentCfId): comment.body
]
])
.asString()
// Updates the issue with the created comment author
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(lastProjectReportCommentAuthorCfId): comment.author
]
])
.asString()
// Updates the issue with the created comment date/time
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(lastProjectReportCommentDateTimeCfId): comment.created
]
])
.asString()
I tried stuff like this but that did not work:
// Updates the issue with the created comment body
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(ProjectReportCommentCfId): comment.body + " " + comment.author + " " + comment.created
]
])
.asString()
Any ideas? Thank you for your insight!
Hi Ward,
What type of field is last comment if its a text field to add new lines you will need to use a new line character of \n.
The page at https://www.baeldung.com/java-string-newline gives examples of how to add new lines to strings in Java and this is what you will need to do.
Also I would advise constructing the string with the new lines in a variable outside of the request to update the field and then just pass this variable when updating the field.
I hope this helps.
Regards,
Kristian
Hi @Ward Schwillens_ Schwillie
just as food for thought: Depending on your exact requirements, there may be apps available in the Atlassian Marketplace that can provide a simpler and more optimised solution for what you're looking for.
If you'd be open to this, you may want to have a look at the app that my team and I are working on, JXL for Jira.
JXL is a full-fledged spreadsheet/table view for your issues that allows viewing, inline-editing, sorting, and filtering by all your issue fields, much like you’d do in e.g. Excel or Google Sheets. It also comes with a number of so-called smart columns that aren’t natively available, including the last comment, date of last comment, last commented by user, and many other comment-related columns.
This is how it looks in action:
As you can see above, you can easily sort and filter by your comment-columns, freely arrange them as it suits you, and also use them across JXL's advanced features, such as support for (configurable) issue hierarchies, issue grouping by any issue field(s), sum-ups, or conditional formatting.
This all just works - there's no scripting or automation whatsoever required.
Any questions just let me know,
Best,
Hannes
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.