Script Listener - Send Custom Email Logic

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

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. 

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...

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

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()

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...

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,946 views 19 22
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you