Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Add customer to group in post function using ScriptRunner

I would like to do check new customer accounts (when their first ticket is created) for a specific email group (i.e. find anyone with an email address from "@example.com") and add them to a specific group.

I have ScriptRunner installed, but I have searched all through their tutorials and examples and can't seem to find anything that would solve this problem. I think it would be as simple as putting a script in the create post function with the following logic:


if email address included "@example.com" then

set group = "distributors"

The part that I can't find is how to look at the email address of a customer/reporter.

1 answer

1 accepted

0 votes
Answer accepted
Hana Kučerová Community Leader Feb 06, 2021

Hi @Paul Mata ,

yes, custom script post-function on create transition should work, please try something like this:

import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.user.ApplicationUser

String USER_GROUP_NAME = "distributors"
String USER_EMAIL_PATTERN = "@example.com"

GroupManager groupManager = ComponentAccessor.getGroupManager()
ApplicationUser reporter = issue.getReporter()
if (reporter.getEmailAddress().contains(USER_EMAIL_PATTERN)) {
Group group = groupManager.getGroup(USER_GROUP_NAME)
if (!groupManager.isUserInGroup(reporter, group)) {
groupManager.addUserToGroup(reporter, group)
}
}

@Hana Kučerová this worked perfectly! Thank you so much for your help.

Like Hana Kučerová likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
4.14.1
TAGS
Community showcase
Published in Jira Service Management

Why upgrade to Jira Service Management Premium?

We often have questions from folks using Jira Service Management about the benefits to using Premium. Check out this video to learn how you can unlock even more value in our Premium plan.  &nb...

209 views 1 6
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you