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

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 Join to answer
Community showcase
Emilee Spencer
Published 8 hours ago in Marketplace Apps

Marketplace Spotlight: DeepAffects

Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...

30 views 0 3
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot