Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner Cannot find matching method ProjectManager#getProjectObjByKey Edited

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?

1 answer

1 accepted

0 votes
Answer accepted

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. 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

97 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you