I'm working on a Scripted Field that will combine the last two comments on an issue and store them in a multi-line text field. The newline formatting is important, so that the two comments can easily be distinguished from each other (if I didn't are about the newlines, I would be using a single-line text field).
No matter what I try, though, I can't get the newlines to work. Everything in my field just ends up all on one line. This is what I'm using for the scripted field (pardon my inefficient coding, this is just my first shot at this):
import com.atlassian.jira.component.ComponentAccessor def commentManager = ComponentAccessor.getCommentManager() def comments = commentManager.getComments(issue) def combined = "" combined += comments[comments.size - 2].getUpdated().format('MM/dd/yyyy').toString() + " - " + comments[comments.size - 2].getAuthorFullName() + ":\n" combined += comments[comments.size - 2].getBody() + "\n\n" combined += comments.last().getUpdated().format('MM/dd/yyyy').toString() + " - " + comments.last().getAuthorFullName() + ":\n" combined += comments.last().getBody() return combined
I would expect the format to come out like this:
05/13/2015 - Jordan Packer:
This is the second-to-last comment on the issue.
05/13/2015 - Jordan Packer:
This is the last comment on the issue.
Community moderators have prevented the ability to post new answers.
This seems to be working to create a line break: "\\n". So why don't you use that? What template does the script field use, eg plain text or html?
Thanks, Jamie. Although your suggestion didn't work for me, it led me to what I needed. I had the scripted field to use the Text Field (multi-line) template, but I had forgotten that I could use HTML instead. I switched to that template and just used </br> instead of /n. It's working now, so thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Although I wish I could get the linebreaks from the comments to be preserved in my new field.... any tips there, @Jamie Echlin [Adaptavist]?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jordan. Can you tell me exactly how you did it with the <\br>? I can't seem to get it to work myself. Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just replaced all of my newline characters (\n) with </br> (make sure you use a forward slash, not a back slash, just like in regular HTML). I then changed the template for my scripted field to HTML. That's all it took for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try what Udo suggested, but place a space after the "\\". I had some trouble getting this to work when I was trying to format multiline text fields. This was one thing that seemed to help for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry that didn't help! Good to know of the future!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See the answer in this question:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried that.... my field ends up just getting two slashes and no line break....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.