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.

2 answers

1 accepted

0 votes
Accepted answer

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!

Hi,

Please help on my code, It was working from last 2 months but suddenly it has stopped working.

I have tried to use behaviour , but after using behaviour function it stopped working so I deleted that behaviour.

But even after deleting it , the post function is not working.

Please check my code and error I have faced.

please help immediately my production is facing issues due ti thiserrorCode.JPGerrorPF.JPG

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Jira Service Desk

Frequently Asked Questions for Jira Service Desk (AKA JSD FAQ)

Just the FAQs! Welcome to the Community, and this Focused-FAQ! Here, we've pulled together some of the most frequently asked questions associated with Jira Service Desk (JSD). We hope ...

96 views 0 8
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