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.
×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
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
Thanks a lot Aidan, that worked - cheers
Now to the next hurdles in the script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.