Forums

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

It is necessary to add a group with users instead of one user in the same field, it is desirable, wh

Alibek Malikov July 9, 2019

I use this script to add users for the selected component, everything works, but now I need to add a group and not a user, what do I need to change to make everything work?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cf = ComponentAccessor.customFieldManager.getCustomFieldObject(10032L); //Соисполнители
def arrayOfComponents = issue.getComponents();
def userList = getCustomFieldValue(issue,10032L)?:[];

for(def comp in arrayOfComponents){
if(comp.getName()=="Email (Почта)"){
userList += [getUser("r.sheraliev")];
}
if(comp.getName()=="FTP (Uzmobile)"){
userList += [getUser("a.malikov")];
}
if(comp.getName()=="AD (Домен)"){
userList += [getUser("o.gulomkodirov")];
}
if(comp.getName()=="JIRA (Confluence)"){
userList += [getUser("m.zaxidov")];
}
if(comp.getName()=="Local Administartor"){
userList += [getUser("o.shodmonov")];
}
if(comp.getName()=="Oasis"){
userList += [getUser("a.malikov")];
}
}

issue.setCustomFieldValue(cf, userList.collect{it})
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)


ApplicationUser getUser(String userName){
return ComponentAccessor.getUserManager().getUserByName(userName)
}
def getCustomFieldValue(issue, Long fieldId) {
issue.getCustomFieldValue(ComponentAccessor.customFieldManager.getCustomFieldObject(fieldId))
}

1 answer

0 votes
Nic Brough -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.
July 9, 2019

What are you trying to add the group to?  The code you've given us only shows what you're doing with users.

Alibek Malikov July 10, 2019

I have components that are written in the script, the components are being added to the users in the field! and it is necessary for me that instead of users groups with users instead of users were added. I apologize for singing English.

Suggest an answer

Log in or Sign up to answer