How do I remove \\ when sending email via scriptrunner post function?

James Porter October 2, 2015

We have a step in our workflow to send an email containing various details to a distribution list.  We achieved this by using the Send Email built in function from scriptrunner, but have found that when the description field on an issue contains \\ then the email step fails to trigger.  I have tried to add the below, but I receive the error: Property '$stringUtils' not found.  

 

Just wondering if anyone can help me to strip out the \\ or replace them so the email will still work?

<tr>
<td>Description:</td>
<td>${$stringUtils.replaceEach(issue.description, "\\", "")}</td>
</tr>

 

Thanks

 

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
JamieA
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.
October 4, 2015

I think it's probably a bug that a single backslash causes an error. Note that two backslashes is a new line in wiki markup.

You can do by using the wiki renderer:

&lt;%   
def rendererManager = com.atlassian.jira.component.ComponentAccessor.getComponent( com.atlassian.jira.issue.RendererManager.class)
def fieldLayoutItem = com.atlassian.jira.component.ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem("description")
def renderer = rendererManager.getRendererForField(fieldLayoutItem)
def desc = renderer.render(issue.description, null)
out &lt;&lt; desc
%&gt;

but not ideal, I'll raise an issue: https://jamieechlin.atlassian.net/browse/GRV-812

1 vote
Jeff Louwerse
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.
October 2, 2015

have you tried using replaceAll in groovy?

I think it would be something like this and I believe you have to escape the backslashes.

issue.description?.replaceAll("\\\\", "")

 

 

 

James Porter October 2, 2015

Thanks, Jeff I tried <tr> <td>Description:</td> <td>${issue.description?.replaceAll("\\\\", "comment")}</td> </tr> It is not giving an error but now, and it successfully sends the email (which is progress), however I am just receiving an empty row on the email. I would have expected (or hoped) it would simple remove the \\?

James Porter October 2, 2015

btw - I tried both ${issue.description?.replaceAll("\\\\", "")} and ${issue.description?.replaceAll("\\\\", "comment")} to see if the empty row would populate with 'comment'... but it did not.

Jeff Louwerse
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.
October 2, 2015

weird it worked for me using the script console. import com.atlassian.jira.component.ComponentAccessor; issue = ComponentAccessor.getIssueManager().getIssueObject("ZAA-2"); issue.description?.toString().replaceAll("\\\\", "comment") produced (it added an extra "comment" but it did work.. probably a better way to escape it or use regex)! I edited this description didn't I??????/ commentcomment what is this commentcomment it worked for me either way but maybe try ${issue.description?.toString().replaceAll("\\\\", "comment")} Have you tried logging the before and after to see what it is doing? Maybe taking the

0 votes
James Porter October 3, 2015

Hi Jeff,  I tried: 

${issue.description?.toString().replaceAll("\\\\", "")}

But I always return an empty cell for Description.  Even when there are no backslashes contained in the text.  The above returns no data on the email body.

I'm completely stuck sad

 

Environment:

Test

Reason for request:

Data-Fix

Summary:

test only - pls ignore

Description:

 

Requester:

James Porter:1

Promoter:

James Porter(james)

Downtime:

none

James Porter October 3, 2015

I've done further testing and the problem isn't related to double backslash...(\\) - I can see now that if there is a single backslash - \, the email will also fail to fire.

James Porter October 3, 2015

this only applies to the description field it seems...

Jeff Louwerse
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.
October 3, 2015

did you log the before and after? For all we know this is a an email/HTML issue... which I actually suspect is your problem. You may have to make this HTML safe with some encoding. Since users can log novels in the description, I don't include it in any custom emails.. if they want it, they can click the link! I once used this to render comments.. but I can't remember if this rendered HTML as wiki markep or the other way around? I haven't touched that in years though and never put it into production. String LastComment = componentManager.getCommentManager().getComments(issue).last()?.body; LastComment = componentManager.getInstance().getRendererManager().getRenderedContent("atlassian-wiki-renderer", LastComment.toString(), issue.issueRenderContext); Time for some debug statements to figure out where the problem is!

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events