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.

1 answer

This widget could not be displayed.
Vasiliy Zverev Community Champion Nov 24, 2016

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 ?

Vasiliy Zverev Community Champion Nov 24, 2016

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

Vasiliy Zverev Community Champion Nov 25, 2016

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. 

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)
}
Vasiliy Zverev Community Champion Nov 30, 2016

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 ?

Vasiliy Zverev Community Champion Nov 30, 2016

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.

Vasiliy Zverev Community Champion Dec 01, 2016

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

Vasiliy Zverev Community Champion Dec 01, 2016

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

264 views 1 3
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you