script runner function failed on inline script

Vijay Sridhar May 17, 2016

Hi ,

I am using Custom script in post-function as Inline script to add watchers in create Issue Transition, Inline script does not show any error while saving , but while creating  new ticket it is throwing error in the atlassian-jira.log .

Do i need to do something else for this to get work , kindly help

2016-05-17 19:08:16,825 http-nio-8080-exec-17 ERROR vijay.sridhar 1148x147845x1 t4vsbz 10.10.99.161 secure/CreateIssueDetails.jspa[c.o.s.jira.workflow.ScriptWorkflowFunction]***************************************
2016-05-17 19:08:16,900 http-nio-8080-exec-17 ERROR vijay.sridhar 1148x147845x1 t4vsbz 10.10.99.161 /secure/CreateIssueDetails.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: null, actionId: 1, file: <i nline script> java.lang.NullPointerException

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.user.util.UserManager;

def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
def watchUsers = {usernames ->
usernames.each {
def username = userManager.getUserByKey(it.toString())
watcherManager.startWatching(username, issue)
}
}
def grp_users = ["n26_cust1", "n26_cust2","n26_cust3","n26_cust4","n26_cust5"]
watchUsers(grp_users)


groovy_adding_watchers.png

 

 

1 answer

1 accepted

0 votes
Answer accepted
Vijay Khacharia
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 18, 2016

Can you confirm if you put the post-function as last one?

Vijay Sridhar May 18, 2016

Thanks , it's working ..

what variable should  i use for adding the group ?

Vijay Khacharia
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 18, 2016

I dont get it, do you want to add a group to the watchers list? It is not possible. From the code i see you trying to add a list of users as watchers. This should be fine. Loop through the list and add them individually.

Vijay Sridhar May 18, 2016

Thanks . @Vijay Khacharia

Tried to add Users in Particular group to be added as watchers ,So that when ever user created or deleted in JIRA does not require changes @ script level .

 

JamieA
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 20, 2016

you can get the users from a group with com.atlassian.jira.security.groups.GroupManager#getUserNamesInGroup(com.atlassian.crowd.embedded.api.Group)

Suggest an answer

Log in or Sign up to answer