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. 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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.