Scriptrunner issue object is always null.

Hi, i'm trying to do a post function with a script on create transition using scriptrunner. The script works fine in a script console, but doesn't work in the post function. In a log file i've got these lines:

2016-06-23 03:29:59,479 http-bio-8080-exec-10 DEBUG username 
209x43885x1 1vm5o8z ip /secure/QuickCreateIssue.jspa 
[ScriptRunner AutoAssign] Current issue keynull
2016-06-23 
03:29:59,493 http-bio-8080-exec-10 ERROR username 209x43885x1 1vm5o8z 
ip /secure/QuickCreateIssue.jspa
[scriptrunner.jira.workflow.ScriptWorkflowFunction] 
*************************************************************************************
2016-06-23
 03:29:59,493 http-bio-8080-exec-10 ERROR Fyedorov.k 209x43885x1 1vm5o8z
 ip /secure/QuickCreateIssue.jspa 
[scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function 
failed on issue: null, actionId: 1, file: <inline script>
java.lang.NullPointerException: Cannot get property 'assignee' on null object
        at Script61.run(Script61.groovy:23)
2016-06-23 03:29:59,779 http-bio-8080-exec-10 ERROR 
username 209x43885x1 1vm5o8z ip 
/secure/QuickCreateIssue.jspa 
[scriptrunner.jira.workflow.ScriptWorkflowFunction] 
*************************************************************************************
2016-06-23
 03:29:59,780 http-bio-8080-exec-10 ERROR username 209x43885x1 1vm5o8z
 ip /secure/QuickCreateIssue.jspa 
[scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function 
failed on issue: null, actionId: 1, file: <inline script>
java.lang.NullPointerException: Cannot get property 'issue' on null object
        at Script65.run(Script65.groovy:11)

Issue object is always null. Any ideas? Thanks and sorry for my english, i'm not native speaker.

1 answer

1 accepted

0 vote

We need to see the script really.  (Ideally, letting us know which are lines 23 in the first one, and 11 in the second script)

Here it is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.UserManager

def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()
def issueService = ComponentAccessor.getIssueService()

def defaultAssignee = userManager.getUserByName("somename").getKey()
def projectLead = userManager.getUserByName("anothername").getKey()

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def curIssue = issueManager.getIssueObject(issue.id)

if (!curIssue.assignee) {
    //def validateAssignResult = issueService.validateAssign(user, curIssue.id, defaultAssignee)
    def validateAssignResult = issueService.validateAssign(user, curIssue.id, defaultAssignee)    
    issueService.assign(user, validateAssignResult)
} else {
    //def validateAssignResult = issueService.validateAssign(user, curIssue.id, projectLead)
    def validateAssignResult = issueService.validateAssign(user, curIssue.id, projectLead)
    issueService.assign(user, validateAssignResult)
}

Log record points to line with "if" statement.

Ok, great.  The line above the "if" is wrong, and also redundant, because a post-function already has access to "current issue"

Try removing that line and changing the if to

if ( !issue.assignee ) {

 

So I know it, but the same problem with using only "issue" object.

Ok, you'll need to do some sets of full debugging - on the line before the if, add a line

log.debug(issue)

The output will be ugly, and it'll be in the log that you quoted in your original question, but it should tell us whether there's something wrong with the issue object.

(Oh, you need to add some supporting code at the top of your script to enable logging - see https://www.adaptavist.com/doco/display/SFJ/Set+logging+to+help+debug+your+scripts )

Thank you, helped a lot. I've fixed it. I placed post function after "Creates the issue originally" function and now it works!

Ahh, fantastic!  I should have read the "on create transition" more carefully and rememered to ask you to check the position.  Sorry!

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

188 views 1 11
Read article

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