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

Add customer to group in post function using ScriptRunner

Paul Mata February 4, 2021

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

1 vote
Answer accepted
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 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)
}
}
Paul Mata February 8, 2021

@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
AUG Leaders

Atlassian Community Events