You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
JIRA version is 7.4.2
Scriptrunner version is 5.4.48
Here's some sample code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.project.ProjectManager
import groovy.transform.Field
import com.atlassian.jira.issue.MutableIssue
@Field IssueFactory issueFactory = ComponentAccessor.getIssueFactory()
@Field ProjectManager projectManager = ComponentAccessor.getProjectManager()
String createOperationalAlarmIssue(alarmObject) {
MutableIssue newTask = issueFactory.getIssue()
newTask.setDescription(alarmObject["description"])
newTask.setProjectObject(
projectManager.getProjectObjByKey(alarmObject["bucket"])
)
}
And I get these errors:
[Static type checking] - Cannot find matching method com.atlassian.jira.issue.MutableIssue#setDescription(java.lang.Object). Please check if the declared type is correct and if the method exists.
[Static type checking] - Cannot find matching method com.atlassian.jira.project.ProjectManager#getProjectObjByKey(java.lang.Object). Please check if the declared type is correct and if the method exists.
[Static type checking] - Cannot find matching method com.atlassian.jira.issue.MutableIssue#setProjectObject(java.lang.Object). Please check if the declared type is correct and if the method exists.
What am I missing here?
Do not understand your example, but
...these are just static type checks. Groovy does not know the type of "alarmObject" nor of "alarmObject['...']" (you did not tell him), so considers it as a general object.
But in fact Groovy only needs the correct type at run time so you should not worry about these "errors". If you want to get rid of them, indicate the type of the method arguments...
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.project.ProjectManager
import groovy.transform.Field
import com.atlassian.jira.issue.MutableIssue
@Field IssueFactory issueFactory = ComponentAccessor.getIssueFactory()
@Field ProjectManager projectManager = ComponentAccessor.getProjectManager()
String createOperationalAlarmIssue(alarmObject) {
MutableIssue newTask = issueFactory.getIssue()
String description = alarmObject["description"]
newTask.setDescription(description)
String bucket = alarmObject["bucket"]
newTask.setProjectObject(
projectManager.getProjectObjByKey(bucket)
)
}
Declaring the argument type beforehand solved the issue. I was thrown by the "method not found": but I'm coming to this from a Python background, so perhaps this is a standard error that a Java dev would recognize immediately.
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.