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

0 vote

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

164 views 1 17
Join discussion

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