The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Add customer to group in post function using ScriptRunner

Paul Mata
Contributor
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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Hana Kučerová
Community Champion
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
Contributor
February 8, 2021

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

Like Hana Kučerová likes this
DEPLOYMENT TYPE
SERVER
VERSION
4.14.1
TAGS
AUG Leaders

Atlassian Community Events