Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

how i can get an issue with ID

baptistemuller April 26, 2019

Hello everyone, I would like to know how I can retrieve an issue on Jira from his ID, knowing that with this code I have the following error:

No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getIssueByID() is applicable for argument types: (java.lang.Long) values: [92197] 

"Cannot find matching method" in my script


I’ve tried a lot of other methods, but always the same mistake.

import com.atlassian.jira.issue.Issue

long issueId = 92197
Issue issue = getIssueByID(issueId)

return issue

 

 

 

2 answers

1 accepted

1 vote
Answer accepted
Antoine Berry
Community Champion
April 26, 2019

Hi @baptistemuller ,

Kindly try : 

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
long issueId = 92197
def issue = issueManager.getIssueObject(issueId)
return issue

 Antoine

baptistemuller April 29, 2019

Hi @Antoine Berry

Thank you a lot it works!

Like Antoine Berry likes this
Antoine Berry
Community Champion
April 29, 2019

Glad to help ! If you are satisfied with the answer you may consider marking it as accepted. :)

Antoine

baptistemuller April 29, 2019

its Done, ty!

baptistemuller April 29, 2019

Hello again @Antoine Berry ,

can you tell me why my condition don't pass please ?

Sry to have bothered you.

PS: customFieldValue does have the value "Improvement"

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)

//Issue and CustomField Manager
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
//Issue's Id
long issueId = 92197
//the current issue
Issue issue = issueManager.getIssueObject(issueId)
//CustomField Name
def customField = customFieldManager.getCustomFieldObjectByName("Pre-Qualification")
//Value of the CustomField of the current issue
Object customFieldValue = customField.getValue(issue)

log.debug(customFieldValue)

if(customFieldValue == "Improvement"){
return "customFieldValue == Improvement"
}

 

 

Antoine Berry
Community Champion
April 29, 2019

Hard to tell not having access to the issue details, logging is your best friend here. I suspect your Pre-Qualification field is a select list, so you would have to use the method getValue() since you initially get a LazyLoadedOption object. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)

//Issue and CustomField Manager
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
//Issue's Id
long issueId = 92197
//the current issue
Issue issue = issueManager.getIssueObject(issueId)
//CustomField Name
def customField = customFieldManager.getCustomFieldObjectByName("Pre-Qualification")
//Value of the CustomField of the current issue
Object customFieldValue = customField.getValue(issue)

log.debug("customFieldValue : " + customFieldValue)
log.debug("customFieldValue class : " + customFieldValue.getClass())

if(customFieldValue.getValue() == "Improvement"){
return "customFieldValue == Improvement"
}

Antoine 

Like baptistemuller likes this
baptistemuller April 29, 2019

ok thank you for you're time, I'll think about it.

Antoine Berry
Community Champion
April 29, 2019

Try this script and tell me what you get.

Like baptistemuller likes this
baptistemuller April 29, 2019

Result:

customFieldValue == Improvement

 

Logs(2):

2019-04-29 15:24:06,075 DEBUG [runner.ScriptRunnerImpl]: customFieldValue : Improvement 2019-04-29 15:24:06,076 DEBUG [runner.ScriptRunnerImpl]: customFieldValue class : class com.atlassian.jira.issue.customfields.option.LazyLoadedOption

 it works, thank you a lot!!

Like Antoine Berry likes this
0 votes
Maya Hocherman July 8, 2019

Hi,

 

Can you please share how can I find the issue ID number?

 

Thanks,

Maya

Antoine Berry
Community Champion
July 8, 2019

Hi @Maya Hocherman ,

If you cannot find the answer on this topic, I would suggest you open a new question so we are able to grasp your problem and answer it as precisely as we can.

Antoine

Like Maya Hocherman likes this

Suggest an answer

Log in or Sign up to answer