Using Scriptrunner to assign group based on the value of single list select custom field

Alvin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2018

Hi Community, I need help on assigning group that is based on the value of single list select custom field 

Scenario is 

When I choose a value on single select list (i.e. I have Affected Service as the single select list, then I select Power as the value of it ) , a group will be assigned on that ticket., group will be assigned depending on the value that is selected on Affected Service Field.

 

Currently, I'm using this code to capture the Assignee Field based on the value selected on the Affected Service Field using ScriptRunner Post Function. Is it possible to reuse this code to capture the groups? group will be added on the ticket depending on the value selected. Thanks!

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

String user;

def cfManager = ComponentAccessor.getCustomFieldManager();
def cf = cfManager.getCustomFieldObjectByName("Affected Service");


switch(issue.getCustomFieldValue(cf) as String){
case "Hardware": user = "jiraadmin";break;
case "Salesforce": user = "w00377";break;
case "Mashery": user = "sample";break;
}


issue.setAssignee(ComponentAccessor.getUserManager().getUserByKey(user))

 

 

2 answers

0 votes
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 12, 2018

Hi Alvin,

Can you please clarify with what you are saying about assigning a group to an issue? As Tarun mentioned, you can only set one person as the assignee, not a group. You could add all the users in the group as watchers. You could also have the post-function send a custom email to users in that group to notify them.

Regards,

Josh

Alvin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 12, 2018

Hi Joshua Yamdogo @ Adaptavist, I'm using it on Post Function. What I mean is when I select value on the Affected Service field, a group will tag on the ticket, lets say I have single group picker field with values Support1 Support2 Support3, If the value on Affected Service Field is Sample1 , then the group Support1 will be tag on the ticket. If Sample2, group  Support2 and so on.

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 10, 2018

Hello @Alvin

Where in Jira are you inserting the code? Are you using post-function or script listener?

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 10, 2018

Also, you have mentioned

" Is it possible to reuse this code to capture the groups of the Assignee ? Thanks!"

You can use the group manager to fetch the groups of the assignee but in Jira you can assign the issue only to individual assignee and not groups.

Alvin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2018

Hi @Tarun Sapra, I'm using it on Post Function. What I mean is when I select value on the Affected Service field, a group that is assign on that value will notified, and included on the ticket

Alvin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2018

Suggest an answer

Log in or Sign up to answer