Forum Discussion
nmrao
Champion Level 3
Groovy supports multi line text
def multiLine = '''line1 text next line and one more line''' //Show as is log.info multiLine //Remove new lines / carriage returns def newString = multiLine.replaceAll('\n', '').replaceAll('\r', '') //See the diff with multiLine log.info newString
pizzaTime
5 years agoOccasional Contributor
Yes, but as I am using confluence API to send back : so I have this body to fill
Especially the value in which I am replacing ${Properties#body} by the readme.md text
{ "id" : "${Properties#pageId}", "type" : "page", "status" : "current", "title" : "Markdown test", "body" : { "storage" : { "value" : "<ac:structured-macro ac:name=\"markdown\" ac:schema-version=\"1\" ac:macro-id=\"1234\"><ac:plain-text-body><![CDATA[${Properties#body}]]></ac:plain-text-body></ac:structured-macro>", "representation" : "storage", "_expandable" : { "content" : "/rest/api/content/${Properties#pageId}" } } }, "version":{"number":${Properties#pageVersion}} }
To be more precise I have this readme:
## Title text ## Another Title another text
That I want to convert into :
## Title \n text \n ## Another Title \n another text
So that it can be supplied in the body in my request.
Best regards,
pizzaTime
- nmrao5 years agoChampion Level 3By the way, it appears that it is possible to send an attachment while you are trying with plain text.
See documentation:
https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/
"value":"<p><ac:structured-macro ac:name=\"space-attachments\"/></p>","content":{"id":"1448805348"}}'
SoapUI generates id when user attaches a file to the test case-> test step. - nmrao5 years agoChampion Level 3Ok, what is happening with above request?
- HimanshuTayal5 years agoCommunity Hero
pizzaTime , could you please attach any screenshot of error for better understanding of problem.:)
- pizzaTime5 years agoOccasional Contributor
Let's say this is the readme I want to update :
## Test description This test verifiy : - lorem text
The error is that what the API expects from a readme is :
## Test description \n This test verifiy :\n - lorem text
So from my groovy script I tried to put it in the request.
{ "id" : "${Properties#pageId}", "type" : "page", "status" : "current", "title" : "Markdown test", "body" : { "storage" : { "value" : "<ac:structured-macro ac:name=\"markdown\" ac:schema-version=\"1\" ac:macro-id=\"1234\"><ac:plain-text-body><![CDATA[${Properties#body}]]></ac:plain-text-body></ac:structured-macro>", "representation" : "storage", "_expandable" : { "content" : "/rest/api/content/${Properties#pageId}" } } }, "version":{"number":${Properties#pageVersion}} }
With :
def carriageReturn= '\\n ' fileContents = fileContents.replaceAll('\n',carriageReturn).replaceAll(' \r',"")
Except '\\n' is interpreted as the a carriage return when i want it to be litteraly '\n'
- nmrao5 years agoChampion Level 3Did it work when you replace with '\\n'?
Related Content
- 6 months ago
- 3 years ago
Recent Discussions
- 18 hours ago
- 17 days ago