Receiving Error in Behavior Script "Cannot Invoke method getStatus on a null object" at Create

Nannette Mori December 12, 2022

Jira 8.26.1

Script Runner V 6.56

At Create getting error "Cannot Invoke method getStatus on a null object" at Create in Script Runner Behavior Script

import com.atlassian.jira.issue.*

import com.atlassion.jira.component.*

def issue = getUnderlyingIssue()

def IssueType= getIssueContext().issueType.name

def issuseStatus = issue.getStatus().getName()

def fixVersions = issue.fixVersions

 

I am not a scripter so any assistance on how to resolve the above error will be appreciated

 

1 answer

1 vote
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 12, 2022

Hi @Nannette Mori 

I'm not currently in front of a console, but if not mistaken you are trying to get the status of an issue, before it's creation. No wonder it returns null. It doesn't yet have a status :)

What are you trying to do?

Nannette Mori December 12, 2022

Understood so how do I not get the status at create?

Nannette Mori December 12, 2022

def issue = getUnderlyingIssue 

def issueStatus = issue.getStatus().getName 

 

So I think it is trying to get the status of the current issue

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 12, 2022

You guessed it. Remove the following line

def issueStatus = issue.getStatus().getName 
Nannette Mori December 13, 2022

I can't remove that line I need that getstatus line to get the status of the current issue. 

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 13, 2022

But it doesn't have a status yet. How is it possible to return something else but null?

Let's go again and I hope that you will figure it out:

  • You have a create issue screen -> this is a screen before the issue is created.
  • You populate this issue create screen with fields, but you don't press submit
  • No issue has been created yet, and you are "stuck" on the little circle on your workflow transition. Keep in mind that the create transition hasn't run yet
  • You create a behavior which mess around values during the issue create screen, but before the issue is created
  • You ask from the issue, which is not yet created, to give you its status
  • The issue will return and will tell you "Hey dudette... I've got no status yet. So here's a null for you"
Nannette Mori December 13, 2022

I understand that at create issue the issue type and status are unknown.  But the Behavior fires at the Create issue event.  You really don't need to be condescending.  You told me to remove the 

def issueStatus = issue.getStatus().getName 

I was just telling you that I need that line.  

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 13, 2022

Sorry if you misunderstood my reply. There wasn't any bad intention to it. The behaviour doesn't fire at the issue created event. The issue created event is fired as a post function after the transition takes place. You want to keep that line and that's fine. But to answer your initial question, you can't solve this problem, because that line, where you've placed it, will always return null.

If you describe your business requirement and what you want to achieve, I might be able to help you out.

Nannette Mori December 13, 2022

We are using a behavior to validate at certain states that the fix version is a valid delivery version.  We want to use a behavior because when you use a validator on a transition the users can update the Fix version back to an invalid delivery in-between transitions in the edit screen

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.22.6
TAGS
AUG Leaders

Atlassian Community Events