Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Script does not work after upgrading to JIRA 7.x

werner kolze November 15, 2018

Hi all - 

we have upgraded to JIRA 7.7.2

and Scriptrunner 5.4.12

I am trying to create a new issue with this small script :

please note: all commented lines are attempts to create a new issue in a different way.

[ START OF SCRIPT ]

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.MutableIssue;


def IssueFactory issueFactory = ComponentAccessor.getIssueFactory();

//def issueFactory = ComponentAccessor.getComponent(IssueFactory.class);
def MutableIssue newissue;

//def newissue = issueFactory.getIssue();
//def MutableIssue newissue = issueFactory.getIssue();
//log.debug(newissue)

return newissue

[ END OF SCRIPT ]

 

the script returns null - 

the logfile shows this WARN message - but I dont know how this is related, I googled it and found an article, but it does not make sense.

here is the WARN message: well, part of it, I removed ip addresses etc

[c.atlassian.ozymandias.SafePluginPointAccess] Unable to run plugin code because of 'java.lang.NullPointerException - null'.


here is the link of the article I found:
https://confluence.atlassian.com/jirakb/nullpointerexception-when-creating-issue-editing-issue-move-issue-accessing-the-screen-tab-from-the-project-296097082.html

 

What is wrong with the script?

thanks in advance

Werner

 

 

1 answer

1 vote
Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 15, 2018

Hiya there Werner! :D

I think you may be running into trouble because you technically aren't ever creating the issue. When you use the Issue Factory, you are more-or-less creating the frame for an issue; but you aren't ever committing it to the database. To do this, you need to use the IssueManager. I have some sample code on-hand that may help out:

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.issueManager
def projectManager = ComponentAccessor.projectManager
def issueFactory = ComponentAccessor.issueFactory
def constantsManager = ComponentAccessor.constantsManager

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

def project = projectManager.getProjectObjByName("Test Project")
def issueTypes = project.getIssueTypes()
def priorities = constantsManager.priorities

def issue = issueFactory.getIssue()
issue.setProjectObject(project)
issue.setIssueType(issueTypes.findByName("Bug"))
issue.setSummary("Test Issue")
issue.setReporter(currentUser)
issue.setPriority(priorities.findByName("Medium"))

//This is where you create the object
issueManager.createIssueObject(currentUser, issue)

Take a look over that and try adapting it for your purposes. Then play around with it and let me know how everything goes! :)

Best,
Aidan

werner kolze November 15, 2018

Thanks a lot Aidan, that worked - cheers

Now to the next hurdles in the script.

Aidan Derossett [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 15, 2018

No problem friend,

The inner-workings of JIRA's more obscure APIs aren't particularly intuitive haha. Best of luck with the rest of your scripting. :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events