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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,459
Community Members
 
Community Events
184
Community Groups

Replace a String with an line break in multi line field

Hello together, 

we are currently facing a problem in our internal Jira environment. We receive data from an external system and they are not possible to send it with line breaks via the API. The problem here is that we need every new data set in a new line because we have some automation scripts reading this line break. 

So now my question is: How can i replace a String with a line break? Maybe this is something I could implement via ScriptRunner. 

The current format is this: 

Hello\nthis\nis\na\test

And the expected format would be:

Hello
this
is
a
test 

 Are there any possibilities to change the data in Jira internally. 

Thanks for now, have a nice weekend. 

Best regards!

1 answer

1 accepted

2 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 20, 2021 • edited

Hi @Tobias 

For your requirement, you could try something like this on the ScriptRunner Console:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issue = issueManager.getIssueByCurrentKey('MOCK-1') as MutableIssue
def description = issue.description.replace("\\n", "\n")
issue.setDescription(description)
issueManager.updateIssue(loggedInUser,issue, EventDispatchOption.DO_NOT_DISPATCH,false)

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

The main point is on this line:-

def description = issue.description.replace("\\n", "\n")

You will need to use the replace method to convert the \n parameter in your String which will be read as \\n to \n to enable the line break.

Below is a print screen of the ScriptRunner Console configuration:-

script_console.png

Below are a few test screens:-

1) This is how the text in the Description field is displayed initially:-

image1.png

2) This is how the text in the Description field is after running the code above:-

image2.png

I hope this helps to answer your question. :)

 

Thank you and Kind Regards,

Ram 

Hi @Ram Kumar Aravindakshan _Adaptavist_
thanks for providing this solution it works really well. How to implement this in Jira? I think best would be to trigger it in a transition or what do you think? The best way would be after creation, but I think this could cause some problems. 

Best Regards,

Tobias

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 11, 2022

Hi @Tobias

You can either do it during a Transition, i.e. using the Post-Function or even using the Listener to answer your question.

If you want to do it using the Post-Function, you could even use the Create transition, i.e. once the issue is created, the text will be re-formatted. This shouldn't cause any issues.

Thank you and Kind Regards,

Ram

Like Tobias likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events