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

add user to user list if value in fieled is correctly

Alibek Malikov October 18, 2019

Help with the script, I need to add the user to the field when creating the task, if two values are selected in the field, field I use Selection List (Drop Down)

i'm using script runner

and i have script:

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))
}

 

this script add users to user rist if components use

If i select from field Responsible Services "Branch (Infosystems)" and in the second fieled "AD (Домен)" script must add users to users fieled list

QIP Shot - Screen 006.png QIP Shot - Screen 007.png

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events