Forums

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

Jira last comment without inline images

Roshan Fernando June 26, 2023

Hi,

Is there a way to show the last comment without any inline images in the comment body. I'm using script runner to show the last comment but it displays all the inline images attached to the comment. 

Thanks

2 answers

2 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
June 26, 2023

Hi @Roshan Fernando

To answer your question, there is no simple solution to this. 

You could try something like this:-

import com.adaptavist.hapi.jira.issues.Issues
import com.atlassian.jira.issue.MutableIssue

def issue = event.issue as MutableIssue
def customIssue = Issues.getByKey(issue.key)
def latestComment = issue.comments.last()
def body = latestComment.body

customIssue.update {
def part = body.split('!')
def builder = new StringBuilder()
builder.append(part[0]).append(part[2])
setCustomFieldValue('Sample Multi Line', builder.toString().replaceAll("\n[ \t]*\n", '\n'))
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications

I have tested this code using ScriptRunner's Listener for the Issue Commented event.

Below is a screenshot of the Listener configuration:-

issue_commented_event.png

In the sample code that I have provided, the Comment is split into a list which contains 3 items, i.e. the first line of the comment, the attachment and the second line of the comment.

Since only the text is required, only the first line and second line of the comment are extracted and added to the Multi-Line text field.

Please note the code will need to be modified according to the scenario. If you have multiple attachments added to the comment, you will need to filter it out accordingly.

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Roshan Fernando July 3, 2023 edited

Hi @Ram Kumar Aravindakshan _Adaptavist_,

Thanks for the detailed instructions. Ideally, I want to remove <img src> tags from the script runner post function email. My current configuration looks like this. Unfortunately, the output of the last comment includes attachment links from all inline images. 

Do you know if there's a way to modify the email template so it could only display the email text in HTML format? Please see attached screenshot. My current configuration is as follows,

Condition and Configuration

import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.comments.Comment
import groovy.json.JsonSlurper

final SD_PUBLIC_COMMENT = "sd.public.comment"

def event = event as IssueEvent
def user = event.getUser()
def issueManager = ComponentAccessor.issueManager
def comment = event.getComment()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)

def isExternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT)
.getEntityProperty().getOrNull()

if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
! (props['internal'] as String).toBoolean()
}
else {
null
}
}

if (comment) {
return isExternal(comment)
}

return false

issue.issueType.name == "Email Requests"
currentUser != "testuser"
isUserMemberOfRole(""jira-administrators"")

Email template

 

<% if (mostRecentComment)
    out << mostRecentComment
%>
image.png
0 votes
Hannes Obweger - JXL for Jira
Atlassian Partner
June 27, 2023

Hi @Roshan Fernando

just to put this out there, if you're open to solutions from the Atlassian Marketplace, you may want to take 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 (along with many other comment-related columns). Due to JXL's table-based nature, comments are shown as single-line text without images. This is how looks in action:

comments.gif

As you can see above, you can easily sort and filter by comments, and also use them across JXL's many 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", so there's no scripting or automation whatsoever required.

Any questions just let me know,

Best,

Hannes

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
atlassian, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events