Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I would like to get a select case (switch) groovy script working inside of JETI for outgoing emails

Aaron Whigham November 1, 2018

I am trying to get a groovy script working in a custom outgoing email template.  I need to use a select case because the initial project was built using a single select instead of a cascading select.  Changing the project is not an option.  Therefore, I have to use a switch statement to match the needed values.  I'm using the Jira Email This Issue add-on (JETI). My code is below.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
MutableIssue issue = issue

def $meetingIDField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Meeting ID")
def $meetingID = issue.getCustomFieldValue($meetingIDField)

def $meetingLink
 switch($meetingID) {
  case 1234567890: $meetingLink = 'https://my/room1'; break;
  case 9876543210: $meetingLink = 'https://my/room2'; break;
  case 1234543210: $meetingLink = 'https://my/room3'; break;
  default: $meetingLink = '';}

if($meetingLink != null){
return $meetingLink
}

1 answer

0 votes
Ivan Tovbin
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 2, 2018

1. Create a scripted field which would return a link depending on your meetingId value. 

2. Use your scripted field's value in your email template.

Aaron Whigham November 6, 2018

Hello Ivan,

Your solution looks good.  However, changing the actual project fields was not an option.  Therefore, I was able to get the result I needed by Writing the following code in the Html Edit Velocity Markup and it works well.

 

<p>
#set($meetingID = $issue.getCustomFieldValue("customfield_12345").toString())
#if( $meetingID == '2222222222')
<h2><a href="https://my/meetingroom1">MEETING LINK</a></h2>
#elseif( $meetingID == '1111111111' )
<h2><a href="https://my/meetingroom2">MEETING LINK</a></h2>
#elseif( $meetingID == '3333333333' )
<h2><a href="https://my/meetingroom3">MEETING LINK</a></h2>
#else
<strong>No Meeting Link</strong>
#end
</p>

 

Thank you

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events