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
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:-
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.
Learn moreOnline 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.