Include a custom field with wiki style renderer in custom email template of scriptrunner post functi

Thomas König November 16, 2021

Hi,

in this answer, it is shown how to include the content of a custom field in the custom email template of the scriptrunner post function. So in the custom email template I'm now using

<% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("MyField")) %>

However, MyField is a custom field that uses a wiki style renderer and in the e-mail (which is send as HTML), it just displays the text of the field without any formatting and without any linebreaks.

Is there a way to nicely format a the text from the custom field in the e-mail?

Cheers, Thomas

3 answers

0 votes
Andrey Mayskiy December 6, 2021

Hi @Thomas König ,

 

I resolved the same task with IssueRenderContext -

Condition and Configuration:

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


def rendererManager = ComponentAccessor.getComponent(com.atlassian.jira.issue.RendererManager.class)
def wikiRenderer = rendererManager.getRendererForType("atlassian-wiki-renderer")
def renderContext = new IssueRenderContext(issue)
def myCf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.findByName("my_cf")

//Don't forget to map rendered value:
config.renderedMyCf = wikiRenderer.render(issue.getCustomFieldValue(myCf) as String, renderContext)

Email Template:

${renderedMyCf}

 

Good luck!

Lara Arthur January 7, 2022

Hi Andrey...looking for some feedback on this. I had used this same logic to render my description field a while back and it no longer works. So I tried it with your solution to render a custom field and that is not working either.

Any insight? It's throwing an error saying the variable [renderedMyCf] image.pngis undeclared

 

And of course right after I posted this I actually checked the output via SR preview and it is rendering. Do you know why it's showing the red X though?

0 votes
Thomas König November 18, 2021

I have not found a proper way to do this, yet. However, using the Automation for Jira plugin to send the e-mails allows to at least keep the line breaks from the custom field.

Lara Arthur January 7, 2022

@Thomas König - it does look like Andrey's solution works

0 votes
Florian PEREZ
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.
November 16, 2021

I don't think you can keep the visual form of a customfield since email are not using the same style display with Jira. 

I'll keep an eye on this topic in case i'm wrong but I strongly doubt on this  !  

Keep having fun with Jira ! 

Suggest an answer

Log in or Sign up to answer