Hi Atlassian Team,
We tried with https://confluence.atlassian.com/jirakb/how-to-automatically-add-request-participants-when-creating-an-issue-777026955.html in JIRA 7.2.4 with Script Runner 4.3.13 with JIRA SD 3.2 and we are getting
error on Script Console as:
[Static type checking] - Cannot find mathing method com.atlassian.jira.component.ComponentAccessor#getIssueIndexManager(). Please check it the declated type is right and it the method exists.
Please help, we need to add certain people into request participants once issue is created.
I refactor given code for scriptRunner. Try this:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.issue.MutableIssue CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() def userManager = ComponentAccessor.getUserUtil() def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10001") 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
Hi,
This script is fine there are no errors on script console now, but getting a warning against line 13Err.jpg
also when script runs. it gives me below error.
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2016-11-25 09:06:15,407 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2016-11-25 09:06:15,407 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: SS-672, actionId: 11, file: <inline script> java.lang.NullPointerException
i just thought it might be because the "Request Participant" field is locked.
any clues ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you changed custom field name here:
def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10001")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, i have updated as
def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_17393")
17393 is field id
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you also provide full stack from atlassian-jira.log.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vasiliy,
Thanks for the solution, i am very much new to JIRA Service Desk and i don't know how i can take this full stack log. but this has been resolved now. i was using wrong custom field ID. i set it to correct value and now the script shared by you is working flawlessly. but after giving this solution, there was one more need arise that before adding the request participants to the list there should be issue match condition on Reporter. let's say. if Reporter is A,B,C then add request participants else don't do anything. i am not sure if it's possible or not. i guess you are expert in this. can you help me add this condition to the existing script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See this to find logs: https://confluence.atlassian.com/jira/where-are-the-application-server-logs-16121981.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is new script, i modified to match issue reporter and then update request participant but some how it's giving me an error.
2016-11-30 15:30:10,199 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2016-11-30 15:30:10,199 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: SS-915, actionId: 11, file: <inline script> java.lang.NullPointerException at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896) at com.atlassian.jira.issue.Issue$getCustomFieldValue$1.call(Unknown Source) at Script757.run(Script757.groovy:33)
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() def userManager = ComponentAccessor.getUserUtil() def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_17806") def getUsersAsArray = { def users = ["pravin.mori"] ArrayList<ApplicationUser> userList = new ArrayList<ApplicationUser>() users.each { def user = userManager.getUserByName(it) if(user) { userList.add(user) } } return userList } CustomField reporter = customFieldManager.getCustomFieldObjectByName('Reporter') if (issue.getCustomFieldValue(reporter) == "vivek.janjrukiya") { MutableIssue myIssue = issue ArrayList<ApplicationUser> applicationUsers = getUsersAsArray() myIssue.setCustomFieldValue(requestParticipantsField, applicationUsers) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems that variable issue is not initialised. Where do you run this script? Into post-funciton this variable is defined, but not into a script console.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, i am running this script in Post-function as custom scrip port-function. and writing this script in script console. any idea why it's not running ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you want to run this script into script console you should to create variable issue like that
//comment it into a postfunction Issue issue = ComponentAccessor.getIssueManager().getIssueObject("issue key")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it's dynamic, i mean, when issue is created and reporter is from the list of reporter (A,B,C,D...) then add (X,Y,Z...) users into request participant.
it's not for issue specific.
i am struggling since week to make to work. but somehow it's failing in each try.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just mean that at first it is better to test script into script console. For this it is requred to define variable issue. Do it manually for existing issue. When this script will work into script console then it will be possible to adopt it for a postfunction on create postfunction.
If this script for create transition then add save issue to database postfunciton
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also check if you have build-in postfunction to save issue to databese after script one.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This code is working, please check.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.IssueChangeHolder
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserUtil()
def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10000")
def getUsersAsArray = {
def users = ["user1", "user2"]
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()
log.warn applicationUsers
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
requestParticipantsField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(requestParticipantsField), applicationUsers),changeHolder)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The problem with this script is that when they been copied the < and > been swapped to <" and >" in the code. Please see below codes that will work
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.issue.MutableIssue CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() def userManager = ComponentAccessor.getUserUtil() def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10001") 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)
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() def userManager = ComponentAccessor.getUserUtil() def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_17806") def getUsersAsArray = { def users = ["pravin.mori"] ArrayList<ApplicationUser> userList = new ArrayList<ApplicationUser>() users.each { def user = userManager.getUserByName(it) if(user) { userList.add(user) } } return userList } CustomField reporter = customFieldManager.getCustomFieldObjectByName('Reporter') if (issue.getCustomFieldValue(reporter) == "vivek.janjrukiya") { MutableIssue myIssue = issue ArrayList<ApplicationUser> applicationUsers = getUsersAsArray() myIssue.setCustomFieldValue(requestParticipantsField, applicationUsers) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.