Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner line feed

Tim Bonney
Contributor
June 13, 2023
I have searched for this and am unable to find something as simple as how to insert a line feed within a response in ScriptRunner Console. Can anyone please advise me on how to accomplish this?
I am writing the script in the consolebut, instead of just returning the response data itself, what I'd like to do is prefix a text string to it, along with a couple of line feeds for readability.
What I am getting is:
"Success - Response Status Code & Data is: [expand:renderedFields,...]"
What I would like to see instead is:
Success
Response Status Code is: 200
Response Data is:
[expand:renderedFields,...]
Here is my query, with <insert line feed here> indicating where I wish to place the line feed syntax...
def issueKey = 'VSTA-1'
def issueFieldsGet = get("/rest/api/2/issue/${issueKey}")
    .header('Content-Type', 'application/json')
    .asObject(Map)
if (issueFieldsGet.status == 200) {
    return "Success" + <insert line feed> + "Response Status Code is: " + issueFieldsGet.status + <insert line feed> + "Response Data is: " + <insert line feed> + issueFieldsGet.body
} else {
return "Error - Response Status Code Returned is: " + issueFieldsGet.status
}
Thank you to anyone who can advise.

2 answers

2 accepted

3 votes
Answer accepted
Mohamed Benziane
Community Champion
June 14, 2023

Hi,

If you want a new line you can use "\n"

Tim Bonney
Contributor
June 14, 2023

Thanks Mohamed, but I tried numerous variations of this and none worked. I either got a syntax error or if it returned the content, it simply included the "\n" as part of the return and concatenated it as part of a string. Can you please provide an example illustrating the specific syntax to use?

Examples of the way I am receiving the data back are as follows:

Success\nResponse Status Code is:\n200

or

Response Data is:\n[issueFieldsGet.body content]

Mohamed Benziane
Community Champion
June 14, 2023

Here a screen (i tried it in server)

Script Console.png

Tim Bonney
Contributor
June 14, 2023

Thank you Mohamed. Apologies! This syntax does inf act appear to work fine if I send it to the log tab. However, it does not seem to work in the results window. Is the syntax different for returning the data on screen there than it is to the log?

0 votes
Answer accepted
Piotr October 8, 2024

Using log is not the answer Tim looked in first place.

@Tim Bonney if U R still looking for answer to your original question:

build the strings for your log and result windows apart keeping in mind that:

  • the EOL for the logs is '\n'
  • the EOL for results is '<br/>

example:



String logMessage = " All my lines are here:\n"

String htmlMessage = 'All my lines are here:<br/>

(1..10).each { i ->

     logMessage = logMessage + "* Line ${i} \n"

     htmlMessage = htmlMessage + "* Line ${i} <br/>"

}

log.info(logMessage)

htmlMessage




That being written, I strongly suggest to comment out console part (perhaps build a nice wrapper class?) to prevent polluting code like that in the production...

 

Tim Bonney
Contributor
October 8, 2024

Thanks Piotr Galas. I'll give this a try.

Amy Breen
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 19, 2025

Thanks @Piotr , you just saved me. I was trying to work out the new line character fdor the console for over an hour.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events