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

How can you get a custom email using Scriptrunner to import a table correctly?

NCFMS Renewals September 27, 2018

So I'm attempting to pull the description into the custom email...which is fine, I can pull a jira field without a problem using - ${issue.description}.

The problem is that when a table is in the description, it is imported into the email with deliminators and not the actual table formatting.

How do you get the correct table formatting into the custom email?

Here are some screen shots:

Actual issue description field with table: 

JIRA Description Capture.PNGScriptrunner Preview Custom Email: (using plain text email format)Scriptrunner Custom Email Preview Capture.PNG

Attempted to change the email format to html...but still unsure on how to add html write-up so that the table format is converted correctly.

Help please!

 

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Thanos Batagiannis _Adaptavist_
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, 2018

Hi there, 

The following code will convert the description of issue with key ATG-1 from wiki markup to html

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.RendererManager
import com.atlassian.jira.issue.fields.renderer.IssueRenderContext
import com.atlassian.jira.issue.fields.renderer.JiraRendererPlugin

def rendererManager = ComponentAccessor.getComponent(RendererManager)
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ATG-1")
def wikiRenderer = rendererManager.getRendererForType("atlassian-wiki-renderer")
def renderContext = new IssueRenderContext(issue)

def html = wikiRenderer.render(issue.description, renderContext)

Should be easy to use it in your script runner custom email. If you have difficulties in doing it, ping me

Kind regards, Thanos 

NCFMS Renewals October 9, 2018

Hi Thanos...thank you for the reply.

I copied your script and updated the issue Key with one of mine to test.

Not sure if I'm putting the code in the correct place or not since I'm not seeing a difference in the formatting...see screen shot below.

I've tried adding it in the email template itself but that doesn't work either. The description field is already set for wiki rendering, should I switch this back?

Also...I need it to dynamically pull the information so the Current Issue will be constantly changing. Will the getIssueByCurrentKey("...") dynamically change or will it look for "RMT-330" each time?

Thanks again for your assistance.--Lara

image.png

NCFMS Renewals October 10, 2018

Thanos,

So I added only "<p><br>${helper.render(issue.description)}" in the email template field and now have columns again...see screen shot. However, I'm still not getting actual uniform table lines...

image.png

Aidan Derossett _Adaptavist_
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 22, 2018

Hey there! :D

I've come to clarify some things, as I think I understand the problem that you're having.

The code that Thanos provided needs to be in your "Condition and Configuration" code-block, as you have done. However, in that same code-block you'll want to take the "html" variable and add it to the "config" Map that we provide. By adding it to this Map, you'll be able to access it in the Email template.  After doing that, you'll want to modify the value that you're passing into the "getIssueByCurrentKey" method slightly. Since you want to get the description for the issue being transitioned, you need to pass that method a key for whatever issue is the target of the transition. You can do this by calling the "getKey" method on the "issue" variable that we pass in for you.

FYI: You can see everything that is provided for you by clicking the question mark with a circle around it at the bottom right of the code block. :b

Both of these changes are reflected in an example below:

Screen Shot 2018-10-22 at 4.33.57 PM.png

On top of those two changes, you'll want to make sure that you put a condition in that code-block as well. In my case, I always want the script to run, so I just returned "true" at the very bottom of the script. But you can see more examples for writing a description in our documentation.

Then, once you've made those changes to your code, you'll have access to the "descHTML" variable in the Email template, as shown below:

Screen Shot 2018-10-22 at 4.37.17 PM.png

That should do what you're wanting it to. Try it out and let me know how it goes! :)

Best,
Aidan

Like Justin likes this
NCFMS Renewals October 22, 2018

Yay! FINALLY. Woo hoo! 

Thank you so much Aidan. Updates made it work. I now see the table :-).

Appreciate all the help!--Lara

Aidan Derossett _Adaptavist_
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 26, 2018

 

I had just about the same reaction when I got it working too lol.

Always glad to help out! :D
Aidan

0 votes
Rodolfo So November 5, 2020

Hi,

 

Can you share code, i'm trying to replicate this scenario?

 

Appreciate your help on this.

 

Thanks

TAGS
AUG Leaders

Atlassian Community Events