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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Request Participants Script in JIRA 7.2.4 with Script Runner 4.3.13

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.

3 answers

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 ?

Have you changed custom field name here:

def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10001")

Yes, i have updated as 

def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_17393")

17393 is field id

Could you also provide full stack from atlassian-jira.log.

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. 

Like Darius Mikelevičius likes this

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: &lt;inline script&gt;
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&lt;ApplicationUser&gt; userList = new ArrayList&lt;ApplicationUser&gt;()
    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&lt;ApplicationUser&gt; applicationUsers = getUsersAsArray()
myIssue.setCustomFieldValue(requestParticipantsField, applicationUsers)
}

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.

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 ?

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

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.

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

Also check if you have build-in postfunction to save issue to databese after script one.

The problem with this script is that when they been copied the < and > been swapped to &lt" and &gt" 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)
}

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)

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you