Hey all,
I need to create a scripted field [free text] that will copy the last comment made to a ticket whenever comments are made.
Any ideas?
Thanks in advanced
Added.body and got what I needed.
import com.atlassian.jira.component.ComponentAccessor
def commentManager = ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(issue)
if (comments) {
comments.last().body
}
Use getComments() from CommentManager to get a list of all comments and then identify the last comment.
I tried using those 3 exact pieces, but couldn't get the script just right.
I'm not really groovy savvy, so my attempt may have just been a poor one.
thx for the code it is working but now I am trying to reverse it so the comments section can copy the custom field... sorry for the question but i am a newbie thx
@Kathryn Allison, @Henning Tietgens (or anyone ) – do you know if there's a way to show this new scripted field in wiki markup? Some of our users have been using wiki markup within their comments and this new field is awesome as it allows us not have open each ticket to view the comments. However it's displaying the raw text, not sure if that can be configurable/scripted or not as my searches aren't coming up with much. TIA!
@Carol Jones2
I just managed to get this working based on frankensteining various other scripts here and there. Since this discussion is still on the first page of google results for searches on this topic, I'll add a comment here. Have a look at the current state of my scripted field:
import com.atlassian.jira.component.ComponentAccessordef user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()def commentManager = ComponentAccessor.getCommentManager()def rendererManager = ComponentAccessor.getRendererManager()def comments = commentManager.getCommentsForUser(issue, user)if (comments) { rendererManager.getRenderedContent("atlassian-wiki-renderer", comments.last().body, issue.issueRenderContext)}
Changing the returned value to one that uses the renderer manager gave me formatted results. It works just fine if you set the field type to "multi-line text", but you can set it to "HTML" if you want it to be more literally correct. The result is the same for both in JIRA 7.4.
Note, if you copy and use my version of the script, it also contains another modification to restrict which comment is returned based on what each user is permitted to see. Kind of defeats the point of comment visibility levels if this field circumvents them, after all. XD
Hi Guys,
With the codes you have written, were any third party plug-ins used at all?
Thanks
Hi,
yes, you need the ScriptRunner plugin.
Henning
Hi All,
first of all thanks for this nice scripted field!
Do you think that there is a possibility to script a field that will copy all comments?
Kind regards,
Nicole
Yes, you can use commentManager.getComments(issue) to get all comments of an issue.
Hello Henning,
thanks for the fast answer!
Now it works.
It looks like you're new here. Sign in or register to get started.