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,551,671
Community Members
 
Community Events
184
Community Groups

Newline Characters in Summary

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

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.

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