Newline Characters in Summary

Simon König
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.
April 25, 2023

Hi,

I have a Problem with Jira Summary and newline-handling that I need help with:

I would like to automatically populate my summary via Description. For this I used a Skriptrunner behaviour to set my Summary with this code:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cfField = getFieldById(getFieldChanged()) [Field Changed is Description]
String newline = System.getProperty("line.separator");
String cfFieldValue = cfField.getValue()

if(cfFieldValue.contains(newline)){
  cfFieldValue.replaceAll(newline,"")
  if(cfFieldValue.length()>197){
    String CutDesc = cfFieldValue.substring(0,197) + "..."
    getFieldById("summary").setFormValue(CutDesc)
  }
}
if(cfFieldValue.length()>197){
  String CutDesc = cfFieldValue.substring(0,197) + "..."
  getFieldById("summary").setFormValue(CutDesc)
}
else{
  getFieldById("summary").setFormValue(cfFieldValue)
}

After that I am using a Post-Function to create a new Issue out of a Workflow [Create / Clone Issue(s) Post-function].

The argument to set the (New-Issue-)Summary to is the Description of the current Issue. I want it to be copied automatically.

Now I have the problem, that if I use a Description that contains Newline-Characters I get the error that Jira can't handle newlines in Summary's. So I wrote this code to circumvent this (almost the same but here we go):

String newline = System.getProperty("line.separator");
String Description = issue.get("description");

if(issue.get("description").contains(newline)){
Description.replaceAll(newline,"")
if(Description.length()>197){
String CutDesc = Description.substring(0,197) + "..."
return CutDesc
}
}

if(issue.get("description").length()>197){
String CutDesc = Description.substring(0,197) + "..."
return CutDesc
}

else{
return Description
}

 

Now my Problem is: If I use text in the description, that uses newline characters, i.e. Tables, I get a "Create/Clone Issue Exception: Summary contains newline characters" when trying to create my Issue via Post-Function.
My question now: Is my code not working (because testing it in groovy skript seemed to work)?

or

Is jira checking for newline characters before my code can even get to work?

and

How is it even possible that the summary gets a newline character if jira can't handle it at all?

Thanks for any help or Info

 

1 answer

1 accepted

0 votes
Answer accepted
Simon König
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 9, 2023

For anyone interested: I found out, that because the description uses a wiki renderer, the correct term to use for is not what you would think it is: system.getproperties("newline") does NOT work. Instead you have to search and replace for  "\r\n". Both together.

It's not written down in any documentation on atlassians side I could find so here you go.

Simon König
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 9, 2023

To use this, just go:

(in fill summary)

String dsc = issue.get("description")

return dsc.replace("\r\n","")

Suggest an answer

Log in or Sign up to answer