Scriptrunner issue object is always null.

Kirill Fedorov June 22, 2016

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
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 23, 2016

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)

Kirill Fedorov June 23, 2016

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 23, 2016

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 ) {

 

Kirill Fedorov June 23, 2016

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 23, 2016

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 )

Kirill Fedorov June 24, 2016

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 24, 2016

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

Like Dave Liao likes this
0 votes
Ankush Dhingan October 27, 2018

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
TAGS
AUG Leaders

Atlassian Community Events