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

How to config custom wiki fields in scriptrunner post function - create email Edited

Ok, so....I've got a scriptrunner post function email set up to let our Testing team know that the build is ready for testing and that there are defects included that need testing.

I've got no problem pulling the custom field "Fixes Defect/s" (highlighted in screen shot and created as a scripted Issue Picker field) but would like to list them and provide a hyper link as I have with the baseline issues (ie RMT-501 & RMT-499)...see below.

Scriptrunner email.JPGIs this possible?

What I'd actually like it to pull is exactly how it shows up on the ticket itself:

image.png

And see this rich text format transfer from ticket to email

image.png

Instead of looking like this:

image.png

Thanks

 

Condition and configuration:

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(issue.key)
def wikiRenderer = rendererManager.getRendererForType("atlassian-wiki-renderer")
def renderContext = new IssueRenderContext(issue)

config.deschHTML = wikiRenderer.render(issue.description, renderContext)
return true

Script used for email:

<p>Dear QA Testers,</p>
<p>${issue.summary} (<strong><a href="${baseUrl}/browse/${issue.getKey()}">${issue.getKey()}<a/></strong>) for ${issue.getParentObject().getSummary()} has been completed and is ready for QA Testing. </p>
<p>Items that require Quality (QA) testing are listed in the table below.</p>
<p><br>${deschHTML}</p></br>
<p>If this Build Deployment contained fixes for any baseline defects, you may find the <strong>linked defects</strong> below:</p>
</strong>
${issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Fixes Defect/s")
)}</p>
<p>Once testing is complete, ensure that you update your testing subtask as well as the main ticket status.</p>
<p><strong>Please navigate to </strong><strong><a href="${baseUrl}/browse/${issue.getParentObject()}">${issue.getParentObject()}</strong></a> for all release related artifacts.</p>
<p>Regards,</p>
${issue.assignee?.displayName}

 

 

2 answers

Hey there scriptRunner peeps...should I submit a ticket for this or can anyone assist here?

Hi

If I recall correctly the Issue Picker fields that allow multi-selection will return a List of Issue Objects when you get its value.

e.g:

def value = issue.getCustomFieldValue(myField) 

So you should be able to get the value of the field, check it is not null and that it is an instance of a list.
e.g:

if(value && value instanceof List){ //logic }

Then you can iterate over all the issues and create a table HTML structure which you can then add to your email template.

It looks like you are using the built-in "Send a custom email" script so it is not easy to do complex logic in the actual email template area. Instead, you can perform the complex logic in the condition and configuration script area and add the created HTML string to the config map variable which is available in the bindings (click the ? on the bottom right of the script field to see bindings). If you add the string to the config bind variable you can refer to it with the standard $ notation in the email template area.

I have an example method that builds a table of issues with links here. Refer to the "buildHTMLTableOfIssues" method

If you still have problems working this out let me know and I can try to draw up a longer example.

Regards

Matthew

Suggest an answer

Log in or Sign up to answer
TAGS

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