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

How do I treat line break in scriptrunner

Edimara Souza February 2, 2022

I have the follow code in scriptrunner that make a update in a external application through API, but when a field have many paragraphs, there are a break line making the json badly formatted. How do I treat this?


There is the code:

def endpointUrl = "https://xxxxxxxx.com.br/v1/integration/jira/epic/${issue.key}"
def http = new HTTPBuilder(endpointUrl)
def msg_update_epico = ""

http.request(PUT, ContentType.JSON) {
def requestContentType2 = ContentType.JSON
request.addHeader("Authorization: Bearer ${token}", "ContentType: application/json")


def commentManager = ComponentAccessor.getCommentManager()

// body = "{ \"status_id\": \"${status_cvv_id.toString()}"

body = """
{
"status_id": "${status_cvv_id.toString()}",
"name": "${issuesummary}",
"delivery_date": "${devdate_value}",
"username": "${event_username}",
"useremail": "${event_useremail}",
"epic_description": "${issuedescription}",
"Progresso": "${progress.toString()}"

}"""

log.info("POSTING update epic: ${endpointUrl}")
log.info("${body}")
msg_update_epico = JSON.message
//log.debug("Retorno update épico: ${msg_update_epico}")
log.debug("Retorno update épico: Automação executada com sucesso")
}

  when I updated some epic description there is a sent json:

 

 

{
"status_id": "17437",
"name": "Problemas de Lentidão na Integração.",
"data_delivery": "2022-03-25",
"username": "xxxxxxxxxxxx",
"useremail": "xxxxxxxxx@xxxxxxx.com.br",
"epic_description": "O QUE?
Problemas de Lentidão na Integração selecionados na black friday. Otimização do processo de atualização dos dados.

COMO?
Realize o acompanhamento da integração de dados para o WM, faça o acompanhamento dos processos com tempo acima do esperado.

CRITÉRIO DE ACEITE
Evidênciar estudo de tempos e processos acelerados junto à operação do CD
",
"Progresso": "0,00%"

}
 

Is there any whay to treat this break line? 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Tim Perrault
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.
February 2, 2022

Hi @Edimara Souza 

 

I haven't tried it, but could you use the trim method?

 

"epic_description": "${issuedescription.trim()}",

Thanks,

Tim

Edimara Souza February 3, 2022

Hi @Tim Perrault 

 

Its won't work :(

Tim Perrault
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.
February 3, 2022

You could try with replaceAll. Again haven't tried it, but worth a shot.

 

"epic_description": "${issuedescription.replaceAll("(\r\n)", "")}",
Like Edimara Souza likes this
Edimara Souza February 3, 2022

Thanks @Tim Perrault 

 

You are an angel! :)

Tim Perrault
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.
February 3, 2022

@Edimara SouzaI'm so glad it worked for you! Have a great Day!

Like Edimara Souza likes this
TAGS
AUG Leaders

Atlassian Community Events