Forums

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

Auto Share Issue at Creation with Custom User Field

Alexandra Wiechers
Contributor
April 30, 2020

Hi,

I'm trying to auto-share (add to Participant List) certain Jira Service Desk Issue Types when they are created.  It is a customer User-Picker field and I'd like them to get notifications etc... as soon as ticket is created.

I've researched and found the script below but I get an error and it doesn't work - 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import java.util.ArrayList
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.issue.CustomFieldManager

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserUtil()
def requestParticipantsField = customFieldManager.getCustomFieldObject("Approving Manager")
def issueManager = ComponentAccessor.getIssueManager()
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueIndexManager = ComponentAccessor.getIssueLinkManager()
def getUsersAsArray = {
def users = ["ben", "steve"]
ArrayList<ApplicationUser> userList = new ArrayList<ApplicationUser>()
users.each {
def user = userManager.getUserByName(it)
if(user)
{ userList.add(user) }
}
return userList
}
MutableIssue myIssue = issue
ArrayList<ApplicationUser> applicationUsers = getUsersAsArray()
myIssue.setCustomFieldValue(requestParticipantsField, applicationUsers)

 

Error is with this line "def customFieldManager = ComponentAccessor.getCustomFieldManager()"

and Error states - variable "customFieldManager" masks a binding variable of the same name

 

I am by no means a groovy script writer or coder so any help is seriously appreciated in detailed steps.  Thank you!

1 answer

0 votes
Andre Serrano
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.
May 6, 2020

Hi Alexandra,

I will point you to some resources that might be helpful to you:

Adaptavist Library 
It's a website with a collection of groovy scripts you can use in your ScriptRunner. When I'm creating my own script I use this website and it helps me a lot. I hope it helps you too.
https://library.adaptavist.com/

SR Script Webinar
It is a webinar that it happened, showing a senior developer creating a script from scratch and explaining the why's and how's whilst doing it. Again, it helped me a lot at the beginning of my journey writing my own scripts.
https://www.adaptavist.com/webinars/groovy-scripting-for-scriptrunner/

Suggest an answer

Log in or Sign up to answer