Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to put newline in multi-line text field (Scripted Field)

Jordan Packer May 13, 2015

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.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2015

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?

Jordan Packer May 13, 2015

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!

Jordan Packer May 13, 2015

Although I wish I could get the linebreaks from the comments to be preserved in my new field.... any tips there, @Jamie Echlin [Adaptavist]?

Michael Marley May 13, 2015

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.

Jordan Packer May 14, 2015

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.

Michael Marley May 15, 2015

Thanks Jordan. It worked! Have a good weekend.

0 votes
Kian Stack Mumo Systems
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 13, 2015

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. 

Jordan Packer May 13, 2015

That didn't do anything for my problem, sorry.

Kian Stack Mumo Systems
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 13, 2015

Sorry that didn't help! Good to know of the future!

0 votes
Udo Brand
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2015

See the answer in this question:

https://answers.atlassian.com/questions/108151

Jordan Packer May 13, 2015

I tried that.... my field ends up just getting two slashes and no line break....

TAGS
AUG Leaders

Atlassian Community Events