Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

My description field do not preserve line breaks

I made a scriptrunner mail handler to create issues when sent to mail. My client requested to replace the * in desciption to "¤" character so before setting the description of the issue I just  used String x=MailUtils.getBody(message).replace('*', '¤') and passed  x in issueobject.setDescription(x). Now the stars are getting replaced with ¤ but the line breaks are not preserved . How to get the line breaks and replace the character at the same time.

Thanks in advance. 

1 answer

Hi @tapraj

Where exactly do you want the line breakers?

Could you share a dummy message where you want to modify the asterisk to the ¤ symbol?

Thank you and Kind regards,

Ram

Hi Ram,

Thank You for responding. The issue got resolved. 

one of the two resolved the issue I am not sure which one exactly though.

1. I was previously using Outlook Web to send the mails to the mail handler 

switching to Outlook Desktop application resolved the problem

2. I was using replaceAll(regex,string) to convert * to ¤ symbol

Switched to replace('*','¤ ')

Expected:

**********************************
*SYSTEMFEHLER-000022: BATCH-MODUL*
**********************************
...ZEITSTEMPEL:...... 19102020211141

...INT.OPERATION:.... U103-DATEI-NACH-DS
F050 Fehler in Datei: S00524019390110004447070059247
*****************************************
*****ENDE.DES.SYSTEMFEHLERPROTOKOLLS*****
*****************************************

 

Generated:


¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤                                              ¤SYSTEMFEHLER-000011: BATCH-MODUL¤                                              ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤                                              ...ZEITSTEMPEL:...... 19042021094915                                            ...MODULHOSTNAME:.... S1617066                 ZEILE-5:.. ..........................................................F7AG     Das ausgewählte Freigabeobjekt kann nicht mehr bearbeitet werden.      ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤                        ¤¤¤¤¤ENDE.DES.SYSTEMFEHLERPROTOKOLLS¤¤¤¤¤                        ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤                

was generating the description like this :

 

Regards,

Tejasvini

Hi @tapraj,

I have tested out the dummy mail with this code below, and it seems to be working.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.exception.CreateException
import com.atlassian.jira.service.util.ServiceUtils
import com.atlassian.jira.service.util.handler.MessageHandlerContext
import com.atlassian.jira.service.util.handler.MessageUserProcessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.mail.MailUtils

import javax.mail.Message
import javax.mail.internet.InternetAddress

final targetProjectKey = "SAM"
final defaultReporterName = "admin"
final defaultIssueType = "Story"

def messageUserProcessor = ComponentAccessor.getComponent(MessageUserProcessor) as MessageUserProcessor
def userManager = ComponentAccessor.userManager
def projectManager = ComponentAccessor.projectManager
def issueFactory = ComponentAccessor.issueFactory

def subject = message.subject as String

def issue = ServiceUtils.findIssueObjectInString(subject)

if (issue) {
return
}

def project = projectManager.getProjectObjByKey(targetProjectKey)

def user = userManager.getUserByName(defaultReporterName)

def reporterUser = messageUserProcessor.getAuthorFromSender(message) ?: user

def allCcRecipients = message.getRecipients(Message.RecipientType.CC) as List<InternetAddress>

def firstValidUser = allCcRecipients.findResult {
messageUserProcessor.findUserByEmail(it.address)
}

def messageBody = MailUtils.getBody(message).replace("*","¤")

def issueObject = issueFactory.issue
issueObject.setProjectObject(project)
issueObject.setSummary(subject)
issueObject.setDescription(messageBody)
issueObject.setIssueTypeId(project.issueTypes.find { it.name == defaultIssueType }.id)
issueObject.setReporter(reporterUser)

firstValidUser ? issueObject.setAssignee(firstValidUser as ApplicationUser) : log.error ("Unable to retrieve valid user from message CC list, issue will be created without assignee")

try {
(messageHandlerContext as MessageHandlerContext).createIssue(user, issueObject)
} catch (CreateException e) {
log.error "Error creating issue: ", e
}

In my sample code, I am using:-

def messageBody = MailUtils.getBody(message).replace("*","¤")

and it seems to be working.

Below is the output it produced:-

mailbody.png

I hope this helps to answer your question. :)


Thank you and Kind Regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

243 views 2 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you