Script Listener - Send Custom Email Logic

A H March 26, 2015

I have created a Send custom email when an Issue is created.

In the email template I have logic to add or not add items if there is a value present.

For example, if there is an Assignee I have the email send out the Assignees name -
<% if (issue.assigneeUser != null)
{ %>
<b>Assignee: </b> $issue.assigneeUser.displayName<br>
<% } %>

I have a custom user field called Customer. I need the email to check the custom field and see if the person is in the jira-users Group. If the person is in the Group, then I will send the issue URL to the customer. If the person is not part of jira-users group then the URL will not be sent in the email.

How can I check a custom user field for a particular group membership?

Thanks

 

 

2 answers

0 votes
A H April 24, 2015

The following works in the Email Template, however, it is only one part of two. This was only to validate the logic <% if (cfValues['Customer'].name == "jsmith") { %> <b>Ticket Number: </b> http://myserver/$issue<br>;; <% } %> The following will only work in the condition, not the email template. import com.atlassian.jira.component.ComponentAccessor def groupManager = ComponentAccessor.getGroupManager() groupManager.isUserInGroup(cfValues['Customer'].name, 'jira-users') This is what I need in the Email template, however it does not function and generates an error import com.atlassian.jira.component.ComponentAccessor <% if (def groupManager = ComponentAccessor.getGroupManager() groupManager.isUserInGroup(cfValues['Customer'].name, 'jira-users')) { %> <b>Blah: </b> http://myserver/$issue<br>;; <% } %> Any help please...

0 votes
JamieA
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.
March 26, 2015

It's the same in an email template as in any script, more or less.

Use com.atlassian.jira.security.groups.GroupManager#isUserInGroup to check if a user is in a group. Google for the javadoc.

For getting a custom field value there are countless previous questions about this. 

A H April 24, 2015

The following works in the Email Template, however, it is only one part of two. This was only to validate the logic <% if (cfValues['Customer'].name == "jsmith") { %> <b>Ticket Number: </b> http://myserver/$issue<br>;; <% } %> The following will only work in the condition, not the email template. import com.atlassian.jira.component.ComponentAccessor def groupManager = ComponentAccessor.getGroupManager() groupManager.isUserInGroup(cfValues['Customer'].name, 'jira-users') This is what I need in the Email template, however it does not function and generates an error import com.atlassian.jira.component.ComponentAccessor <% if (def groupManager = ComponentAccessor.getGroupManager() groupManager.isUserInGroup(cfValues['Customer'].name, 'jira-users')) { %> <b>Blah: </b> http://myserver/$issue<br>;; <% } %> Any help please...

JamieA
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.
May 1, 2015

your imports need to be in <% %> tags as well.

A H May 1, 2015

I tested the items in <% %> and still get an error - <% import com.atlassian.jira.component.ComponentAccessor def groupManager = ComponentAccessor.getGroupManager() groupManager.isUserInGroup(cfValues['Customer'].name, 'jira-users') import com.atlassian.jira.component.ComponentAccessor %> <% if (def groupManager = ComponentAccessor.getGroupManager() groupManager.isUserInGroup(cfValues['Customer'].name, 'jira-users')) { %> <b>Blah: </b> http://myserver/$issue<br>;;; <% } %> Error Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: GStringTemplateScript3.groovy: 8: unexpected token: def @ line 8, column 11. """; if (def groupManager = ComponentAccessor.getGroupManager() ^ 1 error groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: GStringTemplateScript3.groovy: 8: unexpected token: def @ line 8, column 11. """; if (def groupManager = ComponentAccessor.getGroupManager()

Suggest an answer

Log in or Sign up to answer